Sunday, May 12, 2013

Close or Cancel Workflow Notification

I have written a pl/sql script to cancel or close workflow notifications through wf_notifications API.  The script has 2 parameters (recipient_role, close_type), for e.g. you want to close notifications for specific user then pass parameter of user and type as CLOSE or CANCEL for cancelling notification.

PL/SQL Script

-- ****************************************************************
-- Filename -  WFCloseNotifications.sql
-- Purpose  -  Script of cancel or close workflow notification
-- Module   -  Workflow Administrator
-- ****************************************************************
declare
  -- declare Cursor
  cursor get_notif is select * from wf_notifications where recipient_role='&UserName' and status='OPEN';
  -- Local variables here
  i integer           number(10):=1;
  notification_type   varchar2(10):= '&nType';
begin
 dbms_output.put_line('Executing Procedure');
  -- open cursor to check open notifications which needs to be closed
  for c_get_notif in get_notif
   loop
    begin

    -- Check notificaiton type (close or cancel)
    -- CLOSE  -  This will close information notifications only, all action required notification will not be close
    -- CANCEL -  This will cancel notification, action required notification such as Approve/Reject will be cancelled and cannot be rollback, users will not be able to take actiion on such notification later
    if upper(notification_type)='CLOSE' then
      wf_notification.Close(c_get_notif.notification_id, c_get_notif.recipient_role);
      i:=i+1;
   elsif upper(notification_type)='CANCEL' then
      wf_notification.cancel(c_get_notif.notification_id, c_get_notif.recipient_role);
      i:=i+1;
    end if;
   
    exception
     when others then
      null;
    end;
   end loop;
  
   commit;
   dbms_output.put_line(to_char(i)||' records effected');
   dbms_output.put_line('Procedure Executed Successfully');
end;

5 comments:

  1. Good one, really helpful. Thanks

    ReplyDelete
  2. What happens to the workflow after the notification is cancelled via API? I have a notification with two possible outputs - Approve and Reject.. If I cancel this notification which path would it take?

    ReplyDelete
  3. Super ... I used your code ...
    Thanks .

    ReplyDelete
  4. Did not work for me.... :( !!!!!!

    ReplyDelete
  5. HI,
    have Any PL/SQL Script for PO & PR Approvals?


    Muhammad Ramzan

    ReplyDelete