Wednesday, June 24, 2015

Program to Cancel or close the Notification

CREATE OR REPLACE PROCEDURE Remove_Notifications(
   p_errbuf           OUT VARCHAR2,
   p_retcode          OUT NUMBER,
   p_user_name     IN     VARCHAR2,
   l_from_date     IN     VARCHAR2,
   l_to_date       IN     VARCHAR2,
   p_notifi_type   IN     VARCHAR2)
AS
   --DECLARE
   -- declare Cursor
   p_from_date         DATE := fnd_date.canonical_to_date (l_from_date);
   p_to_date           DATE := fnd_date.canonical_to_date (l_to_date);

   CURSOR get_notif
   IS
      SELECT *
        FROM wf_notifications
       WHERE     recipient_role = p_user_Name
             AND status = 'OPEN'
             AND TRUNC (NVL(Sent_date,begin_date)) BETWEEN p_from_date AND p_to_date;

   i                   NUMBER (10) := 1;
   notification_type   VARCHAR2 (20) := p_notifi_type;        --CANCEL default
BEGIN
   --FND_FILE.PUT_LINE.('Executing Procedure');
   FND_FILE.put_line (FND_FILE.LOG, 'PASSED PARAMERTERS ARE');
   FND_FILE.put_line (FND_FILE.LOG, 'USER NAME' || P_USER_NAME);
   FND_FILE.put_line (FND_FILE.LOG, 'FROM DATE' || P_FROM_DATE);
   FND_FILE.put_line (FND_FILE.LOG, 'TO DATE' || P_TO_DATE);
   FND_FILE.put_line (FND_FILE.LOG, 'NOTIFICATION TYPE' || p_notifi_type);

   -- open cursor to check open notifications which needs to be closed
   FOR c_get_notif IN get_notif
   LOOP
      BEGIN
         -- 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 action on such notifications later

         IF UPPER (notification_type) = 'CLOSE'
         THEN
            wf_notification.Close (c_get_notif.notification_id,
                                   c_get_notif.recipient_role);
            i := i + 1;
            COMMIT;
         ELSIF UPPER (notification_type) = 'CANCEL'
         THEN
            wf_notification.cancel (c_get_notif.notification_id,
                                    c_get_notif.recipient_role);
            i := i + 1;
            COMMIT;
         END IF;
      EXCEPTION
         WHEN OTHERS
         THEN
            FND_FILE.put_line (FND_FILE.LOG, SQLERRM);
      END;
   END LOOP;

   COMMIT;
   -- DBMS_OUTPUT.put_line (TO_CHAR  || ' records effected');
   --DBMS_OUTPUT.put_line ('Procedure Executed Successfully');
END;
/

No comments:

Post a Comment