Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Creating WF Local Roles:

Adhoc roles can be created through PL/SQL from database or they can be created from Applications
using User Management Responsibility. If PL/SQL is used to create roles, all user names and role
names in UPPER case to avoid some errors:

Script to Create an Adhoc Role:

DECLARE
vRole VARCHAR2(100) := 'XAOATESTROLE';
vRoleDesc VARCHAR2(100) := 'XAOATESTROLE';
BEGIN
wf_directory.createAdhocRole( vRole,
vRoleDesc,
NULL,
NULL,
'Test Role for All Oracle Apps users',
'MAILHTML',
'OPERATIONS', --USER NAME SHOULD BE IN
CAPS
NULL,
NULL,
'ACTIVE',
NULL
);

dbms_output.Put_line( 'Created Role'


||' '
||vRole);
COMMIT;
END;
/

Result:

Created Role XAOATESTROLE

Script to validate WF Roles:

SELECT *
FROM WF_ROLES
WHERE name = 'XAOATESTROLE';

SELECT *
FROM WF_USER_ROLES
WHERE role_name = 'XAOATESTROLE';

SELECT *
FROM WF_LOCAL_ROLES
WHERE name = 'XAOATESTROLE';

SELECT *
FROM WF_USER_ROLE_ASSIGNMENTS
WHERE role_name = 'XAOATESTROLE';

Script to Add user to an already existing Adhoc Role:

DECLARE
vRoleName VARCHAR2(100);
vUserName VARCHAR2(100);
BEGIN
vRoleName := 'XAOATESTROLE';
vUserName := 'NAME3';
wf_directory.AddUsersToAdHocRole( vRoleName,
vUserName
);
--User names should be in CAPS
COMMIT;
END;
/

Script to Remove user from an existing Adhoc Role:

DECLARE
vRoleName varchar2(100);
vUserName varchar2(100);
BEGIN
vRoleName := 'XAOATESTROLE';
vUserName := 'NAME3';
WF_DIRECTORY.RemoveUsersFromAdHocRole ( vRoleName,
vUserName --User Name in CAPS
);
COMMIT;
END;
/

Using Adhoc roles in workflow notifications:


Once the Roles are created in the database we can load the Roles from database as discussed from
Oracle Worflow Builder as below:

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.

Modified Package Code:

CREATE OR REPLACE PACKAGE BODY XXAOA_TEST_WF_PKG


AS
PROCEDURE INSERT_PROC( itemtype IN VARCHAR2,
itemkey IN VARCHAR2,
actid IN NUMBER,
funcmode IN VARCHAR2,
resultout IN OUT NOCOPY VARCHAR2)
AS
BEGIN

INSERT INTO xxaoa_test_wf VALUES


(itemtype,itemkey,actid,funcmode,resultout);
--The Attribute Set Code can also be written here but always better to
write where it is triggered from.
resultout := 'SUCCESS';
EXCEPTION
WHEN OTHERS
THEN
WF_CORE.CONTEXT(' XAOATEST ','AOAMAIN_PROCESS'||SQLERRM, itemtype,
itemkey);
resultout := 'Error';
END INSERT_PROC;

PROCEDURE LAUNCH_WORKFLOW ( itemtype IN VARCHAR2,


itemkey IN VARCHAR2,
process IN VARCHAR2
)
AS
BEGIN
--WF_ENGINE.Threshold := -1;

WF_ENGINE.CREATEPROCESS( itemtype,
itemkey ,
process
);
DBMS_OUTPUT.PUT_LINE('Work Flow Created with Itemkey: '|| itemkey||'
Itemtype: '|| itemtype);
--Code for setting the ItemAttribute Role which we have created.
--For setting the Number type Attribute use SetItemAttrNumber
WF_ENGINE.SetItemAttrText ( itemtype,
itemkey ,
'XAOA_TEST_ATTRIBUTE', --Item Attribute
Name
'XAOATESTROLE' --WF Role Name
); -- This can be set even in
Insert Procedure.
WF_ENGINE.STARTPROCESS ( itemtype,
itemkey
);
DBMS_OUTPUT.PUT_LINE('Work Flow Started with Itemkey: '|| itemkey||'
Itemtype: '|| itemtype);
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.PUT_LINE('Error at LAUNCH_WORKFLOW: '||SQLERRM);
END LAUNCH_WORKFLOW;
END XXAOA_TEST_WF_PKG;
/
Sample Code to test the workflow:

DECLARE
lvItemType VARCHAR2(80) := 'XAOATEST';
lvUserId NUMBER := -1;
lvItemKey VARCHAR2(10);
vErrorMsg VARCHAR2(2000);
vErrorCode NUMBER;
BEGIN
lvItemKey := 'XAOA6-12'; -- This should be unique value for this Itemtype
xxaoa_test_wf_pkg.launch_workflow( itemtype => lvItemType,
itemkey => lvItemKey,
process => 'AOAMAIN_PROCESS' -- Main
Runnable process name
);
COMMIT; -- Use commit if we need to see the WF Status from Front End from
workflow Admin Resp
EXCEPTION
WHEN OTHERS
THEN
vErrorCode := SQLCODE;
vErrorMsg := SQLERRM(SQLCODE);
RAISE_APPLICATION_ERROR(20001, vErrorMsg);
END;
/

Result:

Work Flow Created with Itemkey: XAOA6-12 Itemtype: XAOATEST


Work Flow Started with Itemkey: XAOA6-12 Itemtype: XAOATEST

Sample scripts to test the Workflow:

SELECT *
FROM wf_item_attribute_values
WHERE item_type = 'XAOATEST';

SELECT *
FROM wf_items
WHERE item_type = 'XAOATEST';

SELECT *
FROM wf_item_activities_history_v
WHERE item_type = 'XAOATEST';

Once triggered See the below Approval Notification for either Workflow –> Notifications or directly on
the screen depending on the Profile Option setup:
Open the Notification:

Once Approved see the Activity history or Status Diagram from Status Monitor. This can be done at
any stage of the workflow once kicked off. Usually while debugging this is the first place we need to
check and then check in wf tables.
Some of the workflow tables:

WF_LOOKUP_TYPES_TL
WF_MESSAGES

WF_MESSAGE_ATTRIBUTES

WF_NOTIFICATION_ATTRIBUTES

WF_ITEM_ATTRIBUTES

WF_ITEM_ACTIVITY_STATUSES

WF_ITEM_ATTRIBUTE_VALUES

You might also like