Workflow Simpl Example
Workflow Simpl 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 databasetrigger 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.
Create Attributes
Create Functions
Create Notification
Create Messages
Create Roles
Now Click File >Save as, Enter ErpSchools Demo and click OK
Expand the node to see attributes, processes, notifications, functions, Events, Messages and lookup types.
Type: Text
Type: Form
Value: INVIDITM
Enter fields
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
DECLARE
BEGIN
wf_directory.CreateAdHocRole(lv_role,
lv_role_desc,
NULL,
NULL,
MAILHTML,
NULL,
NULL,
ACTIVE,
NULL);
End;
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);
END;
DECLARE
v_role_name varchar2(100);
v_user_name varchar2(100);
BEGIN
v_role_name := ERPSCHOOLS_DEMO_ROLE;
v_user_name := NAME3;
END;
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
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;
ERP_DEMO.LAUNCH_WORKFLOW(ERP_DEMO
,lv_itemkey
,lv_id
,lv_orgid
,lv_item_segment1
);
EXCEPTION
error_code := SQLCODE;
error_msg := SQLERRM(SQLCODE);
RAISE_APPLICATION_ERROR(-20150,error_msg);
END;
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;
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_item_number := item_segment1;
WF_ENGINE.Threshold := -1;
v_master_form_link := wf_engine.getitemattrtext(
,aname
=> ERP_SEND_ITEM_FORM_LINK);
set the attribute values in workflow so that you can use them in notifications
WF_ENGINE.STARTPROCESS(itemtype, itemkey);
error_code := SQLCODE;
error_msg := SQLERRM(SQLCODE);
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
IS
v_GET_ITEM_NUMBER VARCHAR2(1000);
BEGIN
v_GET_ITEM_NUMBER := wf_engine.getitemattrtext(
,aname
=> X_ATTRIBUTE);
resultout:=COMPLETE:||Y';
dbms_output.put_line(Entered Exception);
fnd_file.put_line(fnd_file.log,Entered Exception);
END GET_ITEM_DETAILS;
END ERP_DEMO;