Tuesday, February 3, 2009

Validating notification response

I received a requirement from one of my clients to force the user(approver) to enter the comments value before approving the notification..This notification contains 2 responses (1. Approve, 2. Reject), so when the approver rejects the notification we need to make the Comments field in the notification as mandatatory and the notification should not go to the next stage untill he/she enters the comments field before clicking the Reject button in the workflow notification.

Fix: To implement this we need to write a Post notification function which validates the response and checks whether there is a value included in the response attribute. This post notification function needs to be placed in the workflow package and we need to call it the pl/sql block of the notification.

The code in the Post notification function would looks like this.

--------------------------------------------------------------------

PROCEDURE set_reject_comment (
itemtype IN VARCHAR2,
itemkey IN VARCHAR2,
actid IN NUMBER,
funcmode IN VARCHAR2,
resultout OUT VARCHAR2
)
IS
v_response VARCHAR2 (2000);
l_user_comment VARCHAR2 (2000);
approval_comment EXCEPTION;
BEGIN
/*===================================================================================
This will derive the button by looking at the response from the notification. the WF_ENGINE.CONTEXT_NID variable will tell you the notification ID that is being responded to, and we can derive the response from there.
====================================================================================*/
v_response :=
wf_notification.getattrtext (wf_engine.context_nid, 'RESULT');
/*===================================================================================
This will retrieve the value which is stored in the Approval Comments field by the approver when the reject button is pressed.
====================================================================================*/
l_user_comment :=
wf_notification.getattrtext (wf_engine.context_nid,
'APPROVAL_COMMENT'
);

/*===================================================================================
This block will be fired when the user has pressed the 'Reject' Button and the comments is null and then it will raise the user defined error. And the workflow will not continue untill the user enters value in the comments field for rejection.
===================================================================================*/
BEGIN
IF ( funcmode = 'RESPOND'
AND v_response = 'REJECTED'
AND l_user_comment IS NULL
)
THEN
RAISE approval_comment;
END IF;
EXCEPTION
WHEN approval_comment
THEN
raise_application_error
(-20010,
'Approval Comment Field cannot be Null. Please enter reason for rejection and click reject.'
);
RAISE;
END;

COMMIT;
END set_reject_comment;

--------------------------------------------------------------------

No comments: