Previous  Next          Contents  Index  Glossary  Library

Example: Select Approver

The Select Approver function activity calls a PL/SQL stored procedure named WF_REQDEMO.SelectApprover that determines who the next approver is based on the employee approval hierarchy in the demonstration data model.

Result Type

This activity expects a response of 'T' if an approver is found or 'F' if an approver is not found. The possible responses are defined in a lookup type called Boolean, associated with the Standard item type.

PL/SQL Stored Procedure

The PL/SQL stored procedure that this function activity calls is described in detail below. Each section in the procedure is numbered with the notation 1-> for easy referencing.

  procedure SelectApprover ( itemtype in varchar2,
        itemkey in varchar2,
        actid in number,
        funcmode in varchar2,
        resultout out varchar2 ) is
1-> l_forward_from_username varchar2(30);
  l_forward_to_username varchar2(30);
2-> begin        
  if ( funcmode = 'RUN' ) then  
  l_forward_to_username := wf_engine.GetItemAttrText (  
        itemtype => itemtype,
        itemkey => itemkey,
        aname => 'FORWARD_TO_USERNAME');
3-> if (l_forward_to_username is null) then
    l_forward_to_username := wf_engine.GetItemAttrText (
        itemtype => itemtype,
        itemkey => itemkey,
        aname => 'REQUESTOR_USERNAME');
  end if;    
4-> l_forward_from_username := l_forward_to_username;  
5-> wf_engine.SetItemAttrText (itemtype => itemtype;
        itemkey => itemkey,
        aname => 'FORWARD_FROM_USERNAME';
        avalue => l_forward_from_username);
6-> wf_engine.SetItemAttrText (itemtype => itemtype;
        itemkey => itemkey,
        aname => 'FORWARD_FROM_DISPLAY_NAME';
        avalue => wf_directory.GetRoleDisplayName(l_forward_from_username));
7-> l_forward_to_username := wf_reqdemo.GetManager( l_forward_from_username);
8-> wf_engine.SetItemAttrText (itemtype => itemtype;
        itemkey => itemkey,
        aname => 'FORWARD_TO_USERNAME';
        avalue => l_forward_to_username);
9-> wf_engine.SetItemAttrText (itemtype => itemtype;
        itemkey => itemkey,
        aname => 'FORWARD_TO_DISPLAY_NAME';
        avalue => wf_directory.GetRoleDisplayName(l_forward_to_username));
10-> if (l_forward_to_username is null) then
    resultout :='COMPLETE:F';
  else  
    resultout :='COMPLETE:T';
  end if;
11-> end if;    
12-> if (funcmode = 'CANCEL') then
    resultout :='COMPLETE';
    return;
  end if;
13-> if (funcmode = 'TIMEOUT') then
    resultout :='COMPLETE';
    return;
  end if;
14-> exception
    when others then
      wf_core.context('WF_REQDEMO','SelectorApprover',itemtype, itemkey,actid,funcmode);
      raise;
15-> end SelectApprover;

1-> The local arguments l_forward_from_username, and l_forward_to_username are declared in this section.

2-> If the value of funcmode is RUN, then retrieve the name of the last person that this requisition was forwarded to for approval by assigning l_forward_to_username to the value of the FORWARD_TO_USERNAME item type attribute, determined by calling the Workflow Engine API GetItemAttrText. See: GetItemAttribute.

3-> If the value of l_forward_to_username is null, then it means that the requisition has never been forwarded for approval. In this case, assign it the value of the REQUESTOR_USERNAME item type attribute, determined by calling the Workflow Engine API GetItemAttrText.

4-> Assign l_forward_from_username to the value of l_forward_to_username.

5-> This section assigns the value of l_forward_from_username to the FORWARD_FROM_USERNAME item type attribute by calling the Workflow Engine SetItemAttrText API.

6-> This section calls the Directory Service GetRoleDisplayName API to get the display name of the username stored in l_forward_from_username and assigns that name to the FORWARD_FROM_DISPLAY_NAME item type attribute by calling the Workflow Engine SetItemAttrText API.

7-> This section calls the function GetManager to return the manager of the previous approver stored in l_forward_from_username, from the WF_REQDEMO_EMP_HIERARCHY table and assigns that manager's name to l_forward_to_username.

8-> This section assigns the value of l_forward_to_username to the FORWARD_TO_USERNAME item type attribute by calling the Workflow Engine SetItemAttrText API.

9-> This section calls the Directory Service GetRoleDisplayName API to get the display name of the username stored in l_forward_to_username and assigns that name to the FORWARD_TO_DISPLAY_NAME item type attribute by calling the Workflow Engine SetItemAttrText API.

10-> If l_forward_to_username is null, meaning there is no manager above the previous approver in the hierarchy, then assign resultout to be COMPLETE:F. Otherwise, assign resultout to be COMPLETE:T.

11-> This ends the check on funcmode =' RUN'.

12-> If the value of funcmode is CANCEL, then assign resultout to be COMPLETE.

13-> If the value of funcmode is TIMEOUT, then assign resultout to be COMPLETE.

14-> This section calls WF_CORE.CONTEXT if an exception occurs.

15-> The SelectApprover procedure ends.


         Previous  Next          Contents  Index  Glossary  Library