We have already discussed how we can provide a free text field to approver. Now Our aim is to make the field mandatory.
Basic Requirement
Our old requirement looks like "when a person applies for a leave it should go his/her supervisor for approval. Approver must be able to provide his/her comments for approval or rejection of the requisition(comments optional). Approver must also be able to select the Organization Leave Type from a list of values . If the leave gets rejected, don’t store any information in database."
Now our changed requirement will looks like
"when a person applies for a leave it should go his/her supervisor for approval.Approver must be able to provide his/her approval/rejection comments. The comments must be entered by the approver while rejecting the leave requisition.If he/she rejects the leave requisition without entering comments, then it should raise an application error.If he/she approves the requisition it should be optional.Approver must also be able to select the Organization Leave Type from a list of values . If the leave gets rejected, don’t store any information in database."
Design Appraoch
Following interpretation can be drawn from the above requirement.
1) The comment field is mandatory while rejecting the leave request.
2) The comment field is remain as optional if he/she approves the requisition.
From the above derivation, we are clear that when approver entered his/her response(on button click), we have to check whether he has entered some value in the text box or not.
To implement the above business case we have to learn "Post Notification Function"( commonly known as PNF).
PNF is nothing but a pl/sql procedure that will be called on button click. The procedure is attached with the notification.
Let us first create a procedure then we will attach the same with the notification.
1) Any procedure that is attached with an activity(notification/Function activity) must have following input parameter.We need not to bother about how the parameter values will be passed, the workflow engine takes the responsibility to pass the parameter value when it is called.
ITEMTYPE IN VARCHAR2
ITEMKEY IN VARCHAR2,
ACTID IN NUMBER,
FUNCTMODE IN VARCHAR2,
RESULT_OUT IN OUT VARCHAR2
2) Any procedure that is attached with an activity(notification/Function activity) must have a error handling section.if an exception occurs,so that you can include context information in the error stack to help you locate the source of an error
Wf_Core.CONTEXT(<Package Name>,
<procedure name>,
itemtype,
itemkey,
actid,
functmode);
RAISE;
3) We are almost ready with the format of pl/sql procedure that will be called by workflow process. Now we will build our logic step by step
a) First we have to read which button the performer has pressed. This can be identified by the following API
l_notfication_result := wf_notification.getAttrText(wf_engine.context_nid,
'RESULT');
The API will return the internal name of the lookup code corresponding to button.(as we know buttons are created with the lookup code attached with
message)
b) Now we have to find what is the comment approver has entered.
l_sup_comments:=wf_notification.GetAttrText(nid => wf_engine.context_nid,
aname => 'SUPEVISOR_COMMENT'
);
Here l_notfication_result and l_sup_comments are local variable.
c) Set all the inputs that we have taken from supervisor to corresponding attribute. This is to ensure that in future we can reference or share this value.(Say once it is approved we can share the approver comments and org leave type he/she has selected with employee).
d) Now if the l_notfication_result is 'REJECT' and l_sup_comments is null then we have to raise application error with proper error message.
if l_notfication_result is 'REJECT' and l_sup_comments is not null then we have to set the RESULT_OUT parameter.
While setting the Result_out parameter we must follow the format
RESULT_OUT :='COMPLETE:<Internal name of result>;
e) If the l_notfication_result is 'APPROVE' then set the result_out
4) Our procedure is ready to attach with the workflow. Open the approver notification and attach the procedure in "Function Name" field.
5) validate the design and save it in database.
Now our workflow is ready to test.
6) If the approver clicks on 'Reject' button without entering any comments, it will through an error(as soon below)
Note:- In our workflow we have not created any function that will store the data in custom table once it is approved. It is kept for reader.
Hint:- The functmode in that case will be 'RUN'.