Wednesday, April 24, 2013

Oracleworkflow_copy2

The Lesson 2 of Oracle Workflow training is driven by screenshots.
Thanks to all the responses from Lesson 1 of Oracle Workflows Training. The most promising response was that from Swetha who mentioned that although  
Audio-Visual training is good, however if someone wants to practice the steps as they read then its best to have screenshot. 
Another problem with Audio-Visual is that it is not possible to print such audio-video presentations of macromedia. 
( Many thanks Swetha, I appreciate your sincere views. )

Hence the Lesson 2 of Workflow training is driven by screenshots. Please note that Workflows Training Lesson 1 ( Audio Visual) 
is a pre-requisite for fresh workflow learners.

In this lesson we are going to learn:-
1. How to creates lookups in workflow.
2. How to provide a drop down list in notification to user. User will be select the response(approve or reject) from drop down list.
3. How to make a user enter rejection reason in free text response field within notification.
4. Validate that the value of rejection reason is not null, if user selects rejected. Effectivley this will train you on how to do 
validations on notification responses using pl/sql.

Step 1. Open the Workflow “XX Training Workflow” that we created in lesson one. 
The source code for this is in Workflow Training Lesson 1.

Step 2. Under ItemType” XX Training Workflow”, right click on “Lookup Types” and select New.
Image
Select lookup type XX_MY_RESPONSE_TYPE.
Click on Apply and OK, after having created the Lookup Type.
Image

Step3. Within lookup type, right click and select New, to create two new lookup codes.
Image
Create lookup codes like as below.
Lookup code:XX_APPROVED
Image
Ditto as above for Lookup Code: XX_REJECTED
Image

Step 4. Now lets define two attributes. 
These attributes will later be assigned to workflow message that we created in Training Lesson 1 .

Attribute: XX_RESPONSE_ACTION
Image
Note: This attribute will be used in conjunction with the Lookup Type “XX_MY_RESPONSE_TYPE” to display the drop-down list in notification response. 
Each lookup code value will be presented to the user in notification.

Attribute: XX_RESPONSE_REASON
Image
Note: User will be able to enter a free text response reason. Please note that we will validate the value entered into this Notification response field using PL/SQL. 
For this training, we will validate to ensure that Response Reason is entered if the user decides to reject notification.
Step 5. Drag these two attributes one by one using left mouse click, into the message “PO Information”. You will be prompted with a message box when you drag 
these attributes, simply click OK to those messages. After dragging the two attributes to message, these will appear in Workflow as below.
Image



Step 6. Double click on attribute "XX Response Action" within the Message.
Set type to a value of “Lookup”.
Set Source to a value of “Respond”.
Set Lookup Type to "XX My Response Type"
Image

Now double click on attribute "XX Response Reason" within the message "PO Information".
Set Source to "Respond". Leave everything else to its default value and click on OK.
Image

Step7  Important Note: This Oracle Workflow training lesson is simply trying to depict how to present drop down list for response to notification. 
Ideally, for approvals, you will simply attach a Lookup Type to notification itself.


Double click on notification “PO Notif Info”.
In the Function Name field assign “xxxx_po_wf_training_pkg.xx_validate_response”
Image 

Step 8
Write the pl/sql function as below for xx_validate_response (dont worry, I am attaching the code for this tutorial).
  PROCEDURE xx_validate_response(itemtype IN VARCHAR2
                                ,itemkey  IN VARCHAR2
                                ,actid    IN NUMBER
                                ,funcmode IN VARCHAR2
                                ,RESULT   IN OUT VARCHAR2) IS
    l_nid                  NUMBER;
    l_activity_result_code VARCHAR2(200);
    v_response_reason      VARCHAR2(50);
  BEGIN
    IF (funcmode IN ('RESPOND'))
    THEN
      l_nid := wf_engine.context_nid;
      l_activity_result_code := wf_notification.getattrtext(l_nid
                                                           ,'XX_RESPONSE_ACTION');
      v_response_reason := wf_notification.getattrtext(l_nid
                                                      ,'XX_RESPONSE_REASON');
      IF l_activity_result_code = 'XX_REJECTED' AND
         v_response_reason IS NULL
      THEN
        RESULT := 'ERROR: You must enter rejection reason if rejecting.';
        RETURN;
      END IF;
    END IF;
  EXCEPTION
    WHEN OTHERS THEN
      RESULT := SQLERRM;
  END xx_validate_response;



Step9 Now save the workflow in database.
The definition of Workflow File can be downloaded by right clicking here 
Step 10 Test your workflow. 
The remainder PL/SQL scripts for this training tutorial can be downloaded from Lesson 2 Scripts 
When testing, select "XX Rejected" in response while leaving the rejection reason blank. You will then see the error as below.
Image

No comments:

Post a Comment