Workflow Tutorial

Author

Name:

prudhvi

E-mail:

prudhvi@erpschools.com
 

Bookmark and Share   Email

This article will illustrate how to create or define workflow attributes, notifications, messages, roles or users, functions, processes and last but not the least, how to launch a workflow from PL/SQL. The workflow concepts are better explained using an example.

Overview:

This article will illustrate how to create or define workflow attributes, notifications, messages, roles or users, functions, processes and last but not the least, how to launch a workflow from PL/SQL. The workflow concepts are better explained using an example.

Business Requirement:
When an item is created in inventory, workflow needs to be launched and it should collect the details of the item created and sends a notification to group of users along with the details and link to master item form.

Process flow: When an item is created it will create/insert a record in MTL_SYSTEM_ITEMS_B so create a database trigger on the table and launch workflow from that trigger. All you need to do is create the workflow, create the trigger, pl/sql package, roles and finally create an item in inventory.

  • Open WFSTD and save as new workflow
  • Create Attributes
  • Create Functions
  • Create Notification
  • Create Messages
  • Create Roles
  • Create database trigger
  • Create PL/SQL Package

1) Open WFSTD and save as new workflow:

Workflow Tutorial

Navigation: File >> Open

Workflow Tutorial

Click Browse then navigate to Workflow installation directory

Navigation: Workflow Installation Directory\ WF\DATA\US\WFSTD

Now Click File >Save as, Enter "ErpSchools Demo" and click OK

Right click on WFSTD and select New Item type

Workflow Tutorial

Enter the fields as below

Internal Name: ERP_DEMO

Display Name: ErpSchools Demo

Description: ErpSchools Demo

Workflow Tutorial

Now you will see ErpSchools Demo icon in the Navigator

Workflow Tutorial

Expand the node to see attributes, processes, notifications, functions, Events, Messages and lookup types.

Workflow Tutorial

Double click on Process to open up the properties window as shown below

Workflow Tutorial

Enter the fields

Internal Name: ERPSCHOOLS_PROCESS

Display Name: ErpSchools Process

Description: ErpSchools Process

Workflow Tutorial

Workflow Tutorial

Double click ErpSchools Process Icon

Workflow Tutorial

2)    Create Workflow Attributes:

Navigation: Window menu > Navigator

Workflow Attributes

Right click on Attributes and click New Attribute

Workflow Attributes

Enter the fields

Internal Name: ERP_ITEM_NUMBER

Display Name: Item Number

Description: Item Number

Type: Text

Default Value: Value Not Assigned

Workflow Attributes

Click Apply and then OK

Create one more attribute

Right click on Attributes and click New Attribute

Workflow Attributes

Enter the attribute fields

Internal Name: ERP_SEND_ITEM_FORM_LINK

Display Name: Send Item Form Link

Description: Send Item Form Link

Type: Form

Value: INVIDITM

Workflow Attributes

Click Apply and then OK

3)    Create Workflow Function:

Right click and then click on New Function

Workflow Functions

Properties window will open as shown below

Workflow Functions

Change/Enter the fields as below

Change Item Type to Standard from ErpSchools Demo

Select Internal Name as Start

Remaining fields will be populated automatically

Workflow Functions

Click Apply then OK

Workflow Functions

Again Right click on white space and click New Function

Workflow Functions

Change the properties as below

Item Type: Standard

Internal Name: END

Workflow Functions

Click Apply and then OK

Workflow Functions

Right click on white space and then click New Function

Workflow Functions

Enter the fields

Internal Name: ERP_GET_DETAILS

Display Name: Get New Inventory Item Details

Description: Get New Inventory Item Details

Function Name: erpschools_demo_pkg.get_item_details

Workflow Functions

Click Apply and then OK

Workflow Functions

4)  Create Workflow Notifications:

Right click on white space and then click New Notification

Workflow Notification

Enter fields

Internal Name: ERP_SEND_ITEM_DET

Display  Name: Send Item Detials

Description: Send Item Detials

Message: Sned Item Details Message

Workflow Notification

Click Apply and then OK

5)    Create Workflow Messages:

Right click on Message and click New

Workflow Messages

Properties window will pop up as show below

Workflow Messages

Enter the fields

Internal Name: ERP_SEND_ITEM_DET_MSG

Display Name: Send Item Details Message

Description: Send Item Details Message

Workflow Messages

Go to Body Tab and enter as shown below

Workflow Messages

Click Apply and then OK

Navigation:  Window Menu > Navigator

Select Item Form Link Attribute

Workflow Message

Drag and drop both attributes to "Send Item Details Message"

6) Create Roles:

Adhoc roles can be created through PL/SQL from database or they can be created from Applications using User Management Responsibility. If you use PL/SQL to create roles make sure you give all user names and role names in UPPER case to avoid some problems

·         Script to Create a Adhoc Role

·         Script to Add user to existing Adhoc Role

·         Script to Remove user from existing Adhoc Role

·         Using Adhoc roles in workflow notifications

·         Adhoc Roles Tables

Script to Create a Adhoc Role

DECLARE

lv_role varchar2(100) := 'ERPSCHOOLS_DEMO_ROLE';

lv_role_desc varchar2(100) := ' ERPSCHOOLS_DEMO_ROLE';

BEGIN

wf_directory.CreateAdHocRole(lv_role,

                             lv_role_desc,

                             NULL,

                             NULL,

                             'Role Demo for erpschool users',

                             'MAILHTML',

                           'NAME1 NAME2', --USER NAME SHOULD BE IN CAPS

                             NULL,

                             NULL,

                             'ACTIVE',

                             NULL);

dbms_output.put_line('Created Role' ||' '||lv_role);

End;

/

Script to Add user to already existing Adhoc Role

DECLARE

v_role_name varchar2(100);

v_user_name varchar2(100);

BEGIN

v_role_name := 'ERPSCHOOLS_DEMO_ROLE';

v_user_name := 'NAME3';

WF_DIRECTORY.AddUsersToAdHocRole(v_role_name, v_user_name);

--USER NAMES SHOULD BE in CAPS

END;

Script to Remove user from existing Adhoc Role

DECLARE

v_role_name varchar2(100);

v_user_name varchar2(100);

BEGIN

v_role_name := 'ERPSCHOOLS_DEMO_ROLE';

v_user_name := 'NAME3';

WF_DIRECTORY.RemoveUsersFromAdHocRole(v_role_name, v_user_name); --USER NAMES in CAPS

END;

Using Adhoc roles in workflow notifications:

Navigation: File > Load Roles from Database

Select roles you want to use and then click OK.

Open the notification properties and then navigate to node tab, select performer as the role you just created and loaded from database.

Tables:

·         WF_ROLES

·         WF_USER_ROLES

·         WF_LOCAL_ROLES

·         WF_USER_ROLE_ASSIGNMENTS

7)    Launching workflow from PL/SQL:

First create a database trigger as below to call a PL/SQL procedure from which you kick off the workflow.

  •   Create Database Trigger

CREATE OR REPLACE TRIGGER "ERP_SCHOOLS_DEMO_TRIGGER" AFTER INSERT ON INV.MTL_SYSTEM_ITEMS_B REFERENCING NEW AS NEW OLD AS OLD FOR EACH ROW

DECLARE

   lv_id                 NUMBER          := :NEW.inventory_item_id;

   lv_item_segment1      VARCHAR2(100)   := :NEW.segment1;

   lv_itemtype           VARCHAR2(80)    := :NEW.item_type;

   lv_user_id            NUMBER          := -1;

   lv_itemkey            VARCHAR2(10);

   lv_orgid              NUMBER          :=2; 

   error_msg             VARCHAR2(2000);

   error_code            NUMBER;

BEGIN

   lv_user_id := fnd_global.user_id;

   lv_orgid := fnd_global.org_id;

   lv_itemkey := 1132; -- This should be unique value

   ERP_DEMO.LAUNCH_WORKFLOW('ERP_DEMO'

                       ,lv_itemkey

                       ,'ERPSCHOOLS_PROCESS' --process name

                       ,lv_id

                       ,lv_orgid

                       ,lv_item_segment1                        

                       );

EXCEPTION

   WHEN OTHERS THEN   

         error_code := SQLCODE;

         error_msg  := SQLERRM(SQLCODE);          

      RAISE_APPLICATION_ERROR(-20150,error_msg); 

END;

/

  • Create PL/SQL Package to kickoff workflow

CREATE OR REPLACE PACKAGE APPS.ERP_DEMO IS

  PROCEDURE LAUNCH_WORKFLOW

      (

        itemtype        IN VARCHAR2,

        itemkey         IN VARCHAR2,

        process         IN VARCHAR2,

        item_id         IN NUMBER,

        org_id          IN NUMBER,

        item_segment1   IN VARCHAR2

        );

END ERP_DEMO;

/

CREATE OR REPLACE PACKAGE BODY APPS.ERP_DEMO IS

PROCEDURE LAUNCH_WORKFLOW(

                        itemtype         IN VARCHAR2,

                        itemkey          IN VARCHAR2,

                        process          IN VARCHAR2,

                        item_id          IN NUMBER,

                        org_id           IN NUMBER,

                        item_segment1    IN VARCHAR2

                         )

    IS

    v_master_form_link varchar2(5000);

    v_item_number varchar2(100);

    error_code varchar2(100);

    error_msg varchar2(5000);

    BEGIN

        v_add_item_id := ' ITEM_ID="' || item_id || '"';       

        v_item_number := item_segment1;       

        v_master_form_link := v_master_form_link || v_add_item_id;       

        WF_ENGINE.Threshold := -1;

        WF_ENGINE.CREATEPROCESS(itemtype, itemkey, process);

        -- Get the value of attribute assigned in workflow

        v_master_form_link := wf_engine.getitemattrtext(

                                        itemtype => itemtype

                                        ,itemkey  => itemkey

                                        ,aname    => 'ERP_SEND_ITEM_FORM_LINK');

- assign values to variables so that you can usethe attributes

        v_master_form_link varchar2(5000) := v_master_form_link||':#RESP_KEY="INVENTORY" #APP_SHORT_NAME="INV" ORG_MODE="Y" ';      

        v_master_form_link := v_master_form_link || v_add_item_id;

        --set the attribute values in workflow so that you can use them in notifications

        WF_ENGINE.SetItemAttrText(itemtype, itemkey, 'MASTERFORM', v_master_form_link);

        WF_ENGINE.SetItemAttrText(itemtype, itemkey, 'ERP_ITEM_NUMBER', item_segment1);

        -- start the workflow process

        WF_ENGINE.STARTPROCESS(itemtype, itemkey);

   EXCEPTION WHEN OTHERS THEN 

         error_code := SQLCODE;

         error_msg  := SQLERRM(SQLCODE);

    -- add dbms or fnd_output messages as required

END LAUNCH_WORKFLOW;

-- This procedure will just put the item number into workflow attribute ERP_ITEM_NUMBER

PROCEDURE GET_ITEM_DETAILS(

                       itemtype        IN VARCHAR2,

                       itemkey         IN VARCHAR2,

                       actid           IN NUMBER,

                       funcmode        IN VARCHAR2,

                       resultout       OUT NOCOPY VARCHAR2                                

                         )

    IS

v_GET_ITEM_NUMBER VARCHAR2(1000);

BEGIN

SELECT SEGMENT1 INTO V_GET_ITEM_NUMBER FROM MTL_SYSTEM_ITEMS_B WHERE ROWNUM =1;

WF_ENGINE.SetItemAttrText(itemtype, itemkey, 'ERP_ITEM_NUMBER',v_GET_ITEM_NUMBER );

-- you can use the get function as below.

--v_GET_ITEM_NUMBER := wf_engine.getitemattrtext(

--                                        itemtype => itemtype

--                                        ,itemkey  => itemkey

--                                        ,aname    => 'X_ATTRIBUTE');

resultout:='COMPLETE:'||'Y';

exception when others then

dbms_output.put_line('Entered Exception');

fnd_file.put_line(fnd_file.log,'Entered Exception'); 

END GET_ITEM_DETAILS;

END ERP_DEMO;

/         


Naoufel MAMI

commented on 8/18/2009 8:56:56 AM

Hi,
Thanks a lot for this post.

Please update do somone completed this excercice and wheather it works for him or not? please update.

For me doesn't work? the workflow process doesn't started at all?/

Please help

rgds
Naoufel

   
Commented
Naoufe, Did you create an item to start the workflow? How you are trying to start the workflow?

Thanks
Prudhvi

Sekhar Commented
Hi Prudvi. Thanks for the demo. I ve tried to create Workflow by following the steps you mentioned here.
While saving the workflow into database, it gives following workflow error message - 382: Design validation generated 1 warning(s): You may save invalid definaitions, but they should not be used in running the process.
- 354: SAVE validation failed for activity "ERP_DEMO/ERP_PROCESS".
352: process activity must contain a start activity with no in transitions.
These are the messages.
As expected, this workflow did not run.

Kindly advice.

Kutub

commented on 8/30/2009 7:09:12 AM

Dear Sir,

I did all the setup till shown here. Could you please guide us further.

Thanks in advance.

Regards

   

Kutub

commented on 8/30/2009 7:09:26 AM

Dear Sir,

I did all the setup till shown here. Could you please guide us further.

Thanks in advance.

Regards

   
Commented
Kutub, Just create new item and make sure your workflow is started and running.

Thanks
Prudhvi

sekhar

commented on 10/9/2009 12:33:46 AM

Prudvi, This is further to my previous message about errors while saving workflow to DB.
I don't see that error after I change Start/End property on Node tab of the Start and End functions respectively.

But after doing above changes and I tried to test workflow by creating inventory item. Still I can't find any notification in "Notification Summary" page in INV responsibility from where I created new item.

Am I missing anything ? Please help

   
Commented
login into "workflow administrator" responsibility and check if your workflow is being started or not. Also make sure workflow background process is running in your system.

Divya

commented on 2/23/2010 1:44:30 AM

Hi Pridhvi,
Can you paste a screen shot how to link Start, End and Get New Inventory Item Details as well as the notification.

   

sangamesh

commented on 4/15/2010 1:43:55 AM

i am new to workflow, i have to fire a workflow whne i click on a button in oralce form,so that employee leave information is sent to TL

   

Girish Bhoot

commented on 4/27/2010 6:51:38 AM

Dear,
am new in workflow, i have developed new workflow as per the above screen shot and steps. please lets me know now how to use / run this workflow and how to connect this workflow with the database.
thanks in Advance
if any one have material regarding the workflow creation and semple example for it, please mail me at gdbhoot@hotmail.com
Girish Bhoot

   

Jayaraj

commented on 4/28/2010 6:38:03 AM


Please complete this task. You are wasting our time by giving incomplete documents.

Cheers,
Jayaraj.S

   

krishna

commented on 4/30/2010 12:52:58 PM

Thank You for the detailed article.

I followed the steps written above and i have my workflow up and running.

Krishna.

   
Girish Bhoot Commented
Dear Krishna,

will u help me to do the same.
pl. give me steps by steps guideline for the same. as am not able to perform the same using the above step. so pl. help me. if u have details information, pl. give me. at gdbhoot@hotmail.com

Thanking u in advance
Girish Bhoot

Girish Bhoot

commented on 5/1/2010 11:39:49 PM

Dear Krishna,

will u help me to do the same.
pl. give me steps by steps guideline for the same. as am not able to perform the same using the above step. so pl. help me. if u have details information, pl. give me. at gdbhoot@hotmail.com

Thanking u in advance
Girish Bhoot

   

meerjasa

commented on 5/14/2010 11:37:42 PM

Thank You for the detailed article.

   

appstofusioN

commented on 8/4/2010 12:59:21 PM

Hi Prudhvi,

Half demo is nice but better to complete this Demo otherwise there is no use of your Demonstration. Only waste of time of all users.
Regards,
Raj Yadav

   
1
Comments Box

Name:

Email: