Overview:
This workflow tutorial will illustrate how to create or define a new workflow from scratch including 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 Process
- Create Functions including START and END
- Create Attributes
- Create Messages
- Create Notification
- Create Roles & assign to notification
- Link all activities with in process
- Save workflow to database
- Create database trigger
- Create PL/SQL Package
- Run “Workflow Background Process” Concurrent Program
1) Open WFSTD and save as new workflow:
Navigation: File >> Open
Click Browse then navigate to Workflow installation directory
Navigation: Workflow Installation Directory WFDATAUSWFSTD
Now Click File > Save as, Enter “ErpSchools Demo” and click OK
Right click on WFSTD and select New Item type
Enter the fields as shown in below image
Now you will see ErpSchools Demo icon in the Navigator
Expand the node to see attributes, processes, notifications, functions, Events, Messages and lookup types.
Double click on Process to open up the properties window as shown below
Enter the fields as shown in below image
Click OK
Double click ErpSchools Process Icon to open process window where we can draw our workflow diagram.
Right click on process window and then click on New Function.
Properties window will open as shown below
Change/Enter the fields as shown in below image
Change Item Type to Standard. This is important as we are using START and END functions which came from WFSTD (Standard item type).
Select Internal Name as Start
Remaining fields will be populated automatically.
Go to Node tab and select “Start” from the drop down. This is mandatory and can’t be ignored.
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
Go to Node tab and select “End” from the drop down. This is mandatory and can’t be ignored.
Click Apply and then OK
We will come back to this process window later after we have all components / activities ready to link. for now just close process window and go to navigator
Right click on white space in the process window and then click New Function. Alternatively you can select Functions in Navigator and right click to get “New Function” option
Enter the fields as shown in below image
Click Apply and then OK
We will join these activities later after we have our notification ready.
4) Create Workflow Attributes:
Navigation: Window menu > Navigator
Right click on Attributes and click New Attribute
Enter the fields as shown in below image
Click Apply and then OK
Create one more attribute
Right click on Attributes and click New Attribute
Enter the fields as shown in below image
Click Apply and then OK.
Here INVIDITM form belongs to “Master Item” for from inventory module.
Now we have two attributes ready to use.
click on Message and click New
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”. If you miss this step you will not be able to see the attribute values with in email.
6) Create Workflow Notifications:
Right click on white space in process window and then click New Notification
Enter fields as shown in the below image
Message: Sned Item Details Message
Click Apply and then OK
7) Create Roles and assign it to notification:
Adhoc roles can be created through PL/SQL API’s 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
Alternatively you can use USERNAME directly with in the notification.
If you wish to create User Roles manually then follow the below articles
User Role Creation through API: WF_DIRECTORY API User Role Creation from "User Management" Responsibility: Role Creation
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.
8)Link all activities with in process
Open Process window and join all the activities we created so far. To join one activity to other you need to first select the source activity , right click and drag a line to destination activity.
9)Save workflow to database
There are three different methods to upload a workflow into database. The simple one is from workflow builder tool itself.
Go to File > Save as and choose the option “database”.
Provide your apps user login credentials and click OK.
To understand how to save workflow from a file (.wft) to database and vice versa you can read the below article.
10)Launching workflow from PL/SQL:
Make sure to run "Workflow background process" after item is created. Workflow will get into defered status initially and after workflow background process program is completed it should be in running mode.
Compile the PL/SQL code in database.
First create a database trigger as below to call a PL/SQL procedure from which you kick off the workflow.
–Create Database Trigger
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
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
1 2 3 4 5 6 7 8 9 10 11 |
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; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
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); v_add_item_id varchar2(5000); 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 := 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; / |
Create Inventory Item
Go to Inventory module and create inventory item from master org form.
Run “Workflow Background Process” concurrent program
Go to System administrator responsibility and launch concurrent program “Workflow background process” and choose Yes to the parameter process deferred.