Sunday, 13 August 2017

Create a custom Oracle Workflow in Oracle APPS r12


Purpose: The purpose of this document is to create Oracle custom workflow using Oracle Workflow builder.

Steps:

·         Download and install Oracle workflow builder. We will create (.wft) extension file using Oracle workflow builder.

·         Open the Oracle workflow builder.

·         Set the access level to 0 and check the box for “Allow modification of customized objects”



·         Open (download) 2 standard Item types “Standard” and “Standard Flexfield Workflow” by clicking File -> Open (Ctrl + O).

·          In database section enter database details to connect the builder to the database and click “Ok” button.


·        Save the file on the desktop. Select File -> Save As and give the path and the name of the file. Click on “Ok” button.

·        Right click on the file name and click on “New Item Type”.

·        Enter the details as mentioned in the below image

·        Right click on the “Attributes” and select “New Attribute”.

·        Enter the name, type, length, default value of the attribute.

·         Here we will create 2 attributes:

o    USER_NAME – (To which user the approval is send)

o    #FROM_ROLE – (from which user the approval is initiated)

·         Click on “Ok” button.


·         Right click on “Messages” and select “New Message”.

·         Enter the message name, internal name and then click on “Body” tab.

·         Enter the “Subject” and the message in the “Body” part.

·         To use the variable ‘&’ is followed by variable name (&USER_NAME).

·        Click on “Result” tab and select “Approval” in Lookup Type field. Click on “Ok” button.

·        Drag the attributes (USER_NAME & #FROM_ROLE) to message.

·        Right click on “Notifications” and select “New Notification”.

·        Enter the notification name, select “Approval” in the Result type field and select the message in the Message field. Click on “Ok” button.

·        Right click on “Functions” and click on “New Function”.

·        We will create 2 functions:

o   APPROVE – (Action to take place on Approving)

o   REJECT – (Action to take place on rejecting)



·        Right click on “Processes” and click on “New Process”. Click on “Ok” button.

·        Now, double click on Process (Main Process) icon (Yellow).

·        Now, drag and drop functions, notifications from the list of Items in the navigator. 
·        To create a link between two objects right click on any function and then drag and move the cursor to other function. 
·        Drag “Start” function from the “Standard” item type. 
·        Double click on the “Start” function and click on “Node” tab and set the “Start/End” field to “Start”. Click on “Ok” button.

·        Similarly drag “End” function from the “Standard” item type.

·        Double click on the “End” function and click on “Node” tab and set the “Start/End” field to “End”.  Click on “Ok” button.

·         Similarly drag and drop all the functions and notifications as shown in the image below.

·        Double click on “Approval Notification” click on “Node” tab and select “Item Attribute” in Performer section and select “attribute name” (USER_NAME) in value field.

·         Now we create a package to initiate the workflow, write any logic or action to be completed on workflow.

·         This package contains 3 procedures:
o   LAUNCH_WORKFLOW  - (Initiate workflow)

o   APPROVE – (Approval action)
o   REJECT – (Rejection action)

CREATE OR REPLACE PACKAGE XX_CUSTOM_PKG

IS

PROCEDURE LAUNCH_WORKFLOW(P_APPROVAL_ID NUMBER);

PROCEDURE REJECT (

      itemtype   IN       VARCHAR2,

      itemkey    IN       VARCHAR2,

      actid      IN       NUMBER,

      funcmode   IN       VARCHAR2,

      RESULT     IN OUT   VARCHAR2

   );

PROCEDURE APPROVE (

      itemtype   IN       VARCHAR2,

      itemkey    IN       VARCHAR2,

      actid      IN       NUMBER,

      funcmode   IN       VARCHAR2,

      RESULT     IN OUT   VARCHAR2

   );  

END;

/  

CREATE OR REPLACE PACKAGE BODY XX_CUSTOM_PKG

IS

PROCEDURE launch_workflow (p_approval_id NUMBER)

IS

      l_itemtype               VARCHAR2 (30)   := 'XXCUSTOM';

      l_itemkey                VARCHAR2 (300);
      BEGIN
      l_itemkey := 'XXCUSTOM-K1'; -- it has to be unique

            DBMS_OUTPUT.put_line ('STARTED    ' || l_itemkey);

            wf_engine.createprocess (l_itemtype, l_itemkey, 'MAIN_PROCESS'); 

            fnd_global.apps_initialize (fnd_profile.VALUE ('USER_ID'),

                                  fnd_profile.VALUE ('RESP_ID'),

                                  fnd_profile.VALUE ('RESP_APPL_ID'),

                                  NULL,

                                  NULL

                                 );

            wf_engine.setitemattrtext (itemtype      => l_itemtype,

                                 itemkey       => l_itemkey,

                                 aname         => 'USER_NAME',

                                 avalue        => 'SYSADMIN'

                                );

            wf_engine.setitemattrtext (itemtype      => l_itemtype,

                                 itemkey       => l_itemkey,

                                 aname         => '#FROM_ROLE',

                                 avalue        => 'XXUSER1'

                                );

           wf_engine.startprocess (l_itemtype, l_itemkey);

      COMMIT;

      EXCEPTION WHEN OTHERS

             THEN

             DBMS_OUTPUT.put_line (SQLERRM);

         END launch_workflow;

PROCEDURE REJECT (

      itemtype   IN       VARCHAR2,

      itemkey    IN       VARCHAR2,

      actid      IN       NUMBER,

      funcmode   IN       VARCHAR2,

      RESULT     IN OUT   VARCHAR2

   )

   IS

   L_USER_NAME VARCHAR2(100);

     BEGIN

      L_USER_NAME :=

         wf_engine.getitemattrtext (itemtype      => itemtype,

                                    itemkey       => itemkey,

                                    aname         => 'USER_NAME'

                                   );

      DBMS_OUTPUT.PUT_LINE('Approval rejected by '||L_USER_NAME);

      RESULT := 'COMPLETE:Y';

   EXCEPTION

      WHEN OTHERS

      THEN

         RESULT := 'COMPLETE:Y';

         NULL;

   END REJECT;
PROCEDURE APPROVE (

      itemtype   IN       VARCHAR2,

      itemkey    IN       VARCHAR2,

      actid      IN       NUMBER,

      funcmode   IN       VARCHAR2,

      RESULT     IN OUT   VARCHAR2

   )

   IS

   L_USER_NAME VARCHAR2(100);

BEGIN

         L_USER_NAME :=

         wf_engine.getitemattrtext (itemtype      => itemtype,

                                    itemkey       => itemkey,

                                    aname         => 'USER_NAME'

                                   );

      DBMS_OUTPUT.PUT_LINE('Approval approved by '||L_USER_NAME);

      RESULT := 'COMPLETE:Y';

   EXCEPTION

      WHEN OTHERS

      THEN

         RESULT := 'COMPLETE:Y';

END APPROVE;

END XX_CUSTOM_PKG;

·        Now compile the Package on the server.

·        Save the .wft file on the server.  Click File -> Save As. 
·        In database section give the login credentials. And click on “Ok” button. 
·        Now write the below mentioned code in your PL/SQL program or form to initiate the approval. 
XX_CUSTOM_PKG.LAUNCH_WORKFLOW (P_APPROVAL_ID);

No comments:

Post a Comment