You are on page 1of 32

Workflow Tutorial

1 | 2 | 3| 4 | 5 | 6 | 7 Next>>

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

Open WFSTD and save as new workflow

Navigation: File >> Open

Click Browse then navigate to Workflow installation directory

Navigation: Workflow Installation Directory  WF  DATA  WFSTD

Now Click File  Save as  enter "ErpSchools Demo" and click OK

Right click on WFSTD and select New Item type

Enter the fields as below

Internal Name: ERP_DEMO

Display Name: ErpSchools Demo

Description: ErpSchools Demo

Now you will see ErpSchools Demo icon in the Navigator

Double click on Process to open up the properties window as shown below .Expand the node to see attributes. Messages and lookup types. Events. processes. notifications. functions.

Enter the fields Internal Name: ERPSCHOOLS_PROCESS Display Name: ErpSchools Process Description: ErpSchools Process .

Double click ErpSchools Process Icon Workflow Attributes <<Previous 1 | 2 | 3| 4 | 5 | 6 | 7 Next>> .

Navigation: Window menu  Navigator Right click on Attributes and click New Attribute .

Enter the fields Internal Name: ERP_ITEM_NUMBER Display Name: Item Number Description: Item Number Type: Text Default Value: Value Not Assigned Click Apply and then OK Create one more attribute Right click on Attributes and click New Attribute .

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 .

Click Apply and then OK Workflow Function <<Previous 1 | 2 | 3| 4 | 5 | 6 | 7 Next>> Right click and then click on New Function Properties window will open as shown below .

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 Click Apply then OK .

Again Right click on white space and click New Function Change the properties as below Item Type: Standard Internal Name: END .

Click Apply and then OK Right click on white space and then click New Function .

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 .

Click Apply and then OK Workflow Notification <<Previous 1 | 2 | 3| 4 | 5 | 6 | 7 Next>> Right click on white space and then click New Notification .

Enter fields Internal Name: ERP_SEND_ITEM_DET Display Name: Send Item Detials Description: Send Item Detials Message: Sned Item Details Message .

Click Apply and then OK Workflow Messages <<Previous 1 | 2 | 3| 4 | 5 | 6 | 7 Next>> Right click on Message and click New Message Properties window will pop up as show below .

Enter the fields Internal Name: ERP_SEND_ITEM_DET_MSG Display Name: Send Item Details Message Description: Send Item Details Message .

Go to Body Tab and enter as shown below Click Apply and then OK Navigation: Window Menu  Navigator Select Item Form Link Attribute .

.Drag and drop both attributes to "Send Item Details Message" Adhoc Roles in Oracle Applications Next>> 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'.

--USER NAMES SHOULD BE in CAPS END.CreateAdHocRole(lv_role. 'MAILHTML'. WF_DIRECTORY. --USER NAME SHOULD BE IN CAPS NULL. 'NAME1 NAME2'. NULL). v_user_name). lv_role_desc. NULL. 'ACTIVE'. NULL. v_user_name := 'NAME3'. dbms_output. BEGIN wf_directory. Script to Remove user from existing Adhoc Role . NULL. End. / Script to Add user to already existing Adhoc Role DECLARE v_role_name varchar2(100). 'Role Demo for erpschool users'.AddUsersToAdHocRole(v_role_name. v_user_name varchar2(100). BEGIN v_role_name := 'ERPSCHOOLS_DEMO_ROLE'.put_line('Created Role' ||' '||lv_role).lv_role_desc varchar2(100) := ' ERPSCHOOLS_DEMO_ROLE'.

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 . WF_DIRECTORY. Using Adhoc roles in workflow notifications: Navigation: File  Load Roles from Database Select roles you want to use and then click OK. v_user_name varchar2(100). BEGIN v_role_name := 'ERPSCHOOLS_DEMO_ROLE'. v_user_name := 'NAME3'. --USER NAMES in CAPS END.RemoveUsersFromAdHocRole(v_role_name.DECLARE v_role_name varchar2(100). v_user_name). Open the notification properties and then navigate to node tab.

item_type. EXCEPTION . Launching workflow from PL/SQL <<Previous 1 | 2 | 3 | 4 | 5 | 6 | 7 First Create a database tirgger as below to call a PL/SQL procedure from which you kick off the workflow. error_code NUMBER. -.MTL_SYSTEM_ITEMS_B REFERENCING NEW AS NEW OLD AS OLD FOR EACH ROW DECLARE lv_id NUMBER := :NEW. BEGIN lv_user_id := fnd_global.inventory_item_id.lv_orgid .lv_id .'ERPSCHOOLS_PROCESS' --process name .lv_item_segment1 ). lv_itemkey VARCHAR2(10).user_id. Database Trigger CREATE OR REPLACE TRIGGER "ERP_SCHOOLS_DEMO_TRIGGER" AFTER INSERT ON INV.org_id. lv_item_segment1 VARCHAR2(100) := :NEW. lv_user_id NUMBER := -1. lv_orgid NUMBER :=2.This should be unique value ERP_DEMO.segment1. lv_itemkey := 1132.LAUNCH_WORKFLOW('ERP_DEMO' .lv_itemkey . error_msg VARCHAR2(2000). lv_itemtype VARCHAR2(80) := :NEW. lv_orgid := fnd_global.

END. org_id IN NUMBER. item_id IN NUMBER. itemkey IN VARCHAR2. / PL/SQL Package to kickoff workflow CREATE OR REPLACE PACKAGE APPS. error_msg := SQLERRM(SQLCODE). itemkey IN VARCHAR2. RAISE_APPLICATION_ERROR(-20150. / CREATE OR REPLACE PACKAGE BODY APPS. item_id IN NUMBER.error_msg). process IN VARCHAR2.ERP_DEMO IS PROCEDURE LAUNCH_WORKFLOW( itemtype IN VARCHAR2. item_segment1 IN VARCHAR2 ) IS . process IN VARCHAR2. org_id IN NUMBER. END ERP_DEMO. item_segment1 IN VARCHAR2 ). WHEN OTHERS THEN error_code := SQLCODE.ERP_DEMO IS PROCEDURE LAUNCH_WORKFLOW ( itemtype IN VARCHAR2.

-.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" '.Get the value of attribute assigned in workflow v_master_form_link := wf_engine.STARTPROCESS(itemtype. WF_ENGINE. 'ERP_ITEM_NUMBER'. v_master_form_link := v_master_form_link || v_add_item_id. process). EXCEPTION WHEN OTHERS THEN . --set the attribute values in workflow so that you can use them in notifications WF_ENGINE. . v_master_form_link := v_master_form_link || v_add_item_id.SetItemAttrText(itemtype.CREATEPROCESS(itemtype. error_code varchar2(100). itemkey. v_item_number varchar2(100).SetItemAttrText(itemtype. error_msg varchar2(5000). WF_ENGINE.getitemattrtext( itemtype => itemtype . itemkey. v_item_number := item_segment1. itemkey).start the workflow process WF_ENGINE.aname => 'ERP_SEND_ITEM_FORM_LINK'). 'MASTERFORM'. v_master_form_link).Threshold := -1. itemkey. item_segment1). WF_ENGINE. -. BEGIN v_add_item_id := ' ITEM_ID="' || item_id || '"'. v_master_form_link varchar2(5000).itemkey => itemkey .

This procedure will just put the item number into workflow attribute ERP_ITEM_NUMBER PROCEDURE GET_ITEM_DETAILS( itemtype IN VARCHAR2. itemkey. funcmode IN VARCHAR2.itemkey => itemkey -. . WF_ENGINE. error_code := SQLCODE.aname => 'X_ATTRIBUTE').you can use the get function as below. BEGIN SELECT SEGMENT1 INTO V_GET_ITEM_NUMBER FROM MTL_SYSTEM_ITEMS_B WHERE ROWNUM =1.v_GET_ITEM_NUMBER ).SetItemAttrText(itemtype. . error_msg := SQLERRM(SQLCODE).add dbms or fnd_output messages as required END LAUNCH_WORKFLOW. resultout OUT NOCOPY VARCHAR2 ) IS v_GET_ITEM_NUMBER VARCHAR2(1000).getitemattrtext( -. itemkey IN VARCHAR2. -. -. actid IN NUMBER. 'ERP_ITEM_NUMBER'. . -. --v_GET_ITEM_NUMBER := wf_engine. itemtype => itemtype -.

/ . fnd_file.log.'Entered Exception'). END GET_ITEM_DETAILS.put_line(fnd_file. exception when others then dbms_output.put_line('Entered Exception'). END ERP_DEMO.resultout:='COMPLETE:'||'Y'.

EXCEPTION . error_code NUMBER.MTL_SYSTEM_ITEMS_B REFERENCING NEW AS NEW OLD AS OLD FOR EACH ROW DECLARE lv_id NUMBER := :NEW.item_type.lv_orgid .This should be unique value ERP_DEMO. lv_itemtype VARCHAR2(80) := :NEW. Launching workflow from PL/SQL <<Previous 1 | 2 | 3 | 4 | 5 | 6 | 7 First Create a database tirgger as below to call a PL/SQL procedure from which you kick off the workflow. lv_itemkey := 1132. lv_item_segment1 VARCHAR2(100) := :NEW. lv_user_id NUMBER := -1. lv_itemkey VARCHAR2(10). lv_orgid NUMBER :=2.user_id.'ERPSCHOOLS_PROCESS' --process name .lv_item_segment1 ).LAUNCH_WORKFLOW('ERP_DEMO' . lv_orgid := fnd_global. Database Trigger CREATE OR REPLACE TRIGGER "ERP_SCHOOLS_DEMO_TRIGGER" AFTER INSERT ON INV.segment1. BEGIN lv_user_id := fnd_global. error_msg VARCHAR2(2000).inventory_item_id.org_id.lv_id . -.lv_itemkey .

END. / PL/SQL Package to kickoff workflow CREATE OR REPLACE PACKAGE APPS. process IN VARCHAR2. / CREATE OR REPLACE PACKAGE BODY APPS. WHEN OTHERS THEN error_code := SQLCODE.ERP_DEMO IS PROCEDURE LAUNCH_WORKFLOW( itemtype IN VARCHAR2.error_msg). RAISE_APPLICATION_ERROR(-20150. error_msg := SQLERRM(SQLCODE). item_id IN NUMBER. itemkey IN VARCHAR2. item_id IN NUMBER. item_segment1 IN VARCHAR2 ) IS . process IN VARCHAR2. org_id IN NUMBER. itemkey IN VARCHAR2.ERP_DEMO IS PROCEDURE LAUNCH_WORKFLOW ( itemtype IN VARCHAR2. org_id IN NUMBER. item_segment1 IN VARCHAR2 ). END ERP_DEMO.

v_master_form_link).SetItemAttrText(itemtype. WF_ENGINE. itemkey. error_code varchar2(100). -.CREATEPROCESS(itemtype. v_master_form_link := v_master_form_link || v_add_item_id.Threshold := -1. v_master_form_link := v_master_form_link || v_add_item_id. item_segment1). 'ERP_ITEM_NUMBER'. --set the attribute values in workflow so that you can use them in notifications WF_ENGINE. process).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" '. BEGIN v_add_item_id := ' ITEM_ID="' || item_id || '"'.getitemattrtext( itemtype => itemtype . v_item_number := item_segment1. EXCEPTION WHEN OTHERS THEN . .SetItemAttrText(itemtype. WF_ENGINE. v_master_form_link varchar2(5000). itemkey). itemkey. v_item_number varchar2(100). WF_ENGINE.itemkey => itemkey .start the workflow process WF_ENGINE. 'MASTERFORM'.aname => 'ERP_SEND_ITEM_FORM_LINK').STARTPROCESS(itemtype. error_msg varchar2(5000).Get the value of attribute assigned in workflow v_master_form_link := wf_engine. -. itemkey.

. error_code := SQLCODE. -. error_msg := SQLERRM(SQLCODE). -. resultout OUT NOCOPY VARCHAR2 ) IS v_GET_ITEM_NUMBER VARCHAR2(1000).v_GET_ITEM_NUMBER ).you can use the get function as below.aname => 'X_ATTRIBUTE'). . -.SetItemAttrText(itemtype. itemkey. WF_ENGINE. itemtype => itemtype -. --v_GET_ITEM_NUMBER := wf_engine.add dbms or fnd_output messages as required END LAUNCH_WORKFLOW. funcmode IN VARCHAR2.getitemattrtext( -.This procedure will just put the item number into workflow attribute ERP_ITEM_NUMBER PROCEDURE GET_ITEM_DETAILS( itemtype IN VARCHAR2. . 'ERP_ITEM_NUMBER'.itemkey => itemkey -. itemkey IN VARCHAR2. BEGIN SELECT SEGMENT1 INTO V_GET_ITEM_NUMBER FROM MTL_SYSTEM_ITEMS_B WHERE ROWNUM =1. actid IN NUMBER.

/ .resultout:='COMPLETE:'||'Y'.put_line('Entered Exception').'Entered Exception'). fnd_file.put_line(fnd_file. END ERP_DEMO. exception when others then dbms_output.log. END GET_ITEM_DETAILS.