A question that comes up regularly is what’s the best way to respond / close / abort notifications in bulk. I’ve recently been writing a pretty horrendous workflow for a government organization, and when I was developing the code, needless to say there were a few errors that came out.
The workflow that errored raised the standard error handling workflow, so I ended up with somewhere in the region of 2000 notifications being sent to SYSADMIN. Once the code was fixed, I just wanted a quick way to respond to all of them. Depending on the patch level of the environment, Oracle have introduced a way of bulk responding to notifications via the worklist – however, having to click through the 2000 notifications to select each one is a pretty tedious task 🙂
The WF_NOTIFICATION package contains everything that you need to do to respond to notifications programatically – I’ve used it a lot when responding from Portal and from forms as well. There are two different approaches, depending on whether the notification requires a response or not.
FYI notifications are the easiest – all you need to do is call WF_NOTIFICATION.Close, passing in the notification ID. Since it’s that easy, I’ll credit you with the ability to be able to write your own code to do it!
Notifications which require a response are slightly harder – you need to set the response in the notification, and then tell the engine that the notification has been responded it. Firstly, call WF_NOTIFICATION.SetAttrText to set an attribute called "RESULT" to the value that you are sending back. This needs to be the internal name of the lookup code that you are using. Once you’ve done that, you just need to call WF_NOTIFICATION.Respond to close the notification.
A code sample to retry all open notifications sent from the standard error workflow to the SYSADMIN user is:
FOR i IN ( SELECT notification_id
WHERE recipient_role = 'SYSADMIN'
AND status = 'OPEN'
AND message_type = 'WFERROR'
AND message_name = 'RESET_ERROR_MESSAGE' ) LOOP
wf_notification.setattrtext ( nid => i.notification_id
, aname => 'RESULT'
, avalue => 'RETRY' );
wf_notification.respond ( nid => i.notification_id );