Creating a Workflow from scratch
Creating a New workflow using WFSTD:
Download the Standard Workflow for creating a new workflow item type:
To download the workflow file we can download using wfload or from Oracle Workflow Builder.
Navigation:
File –> Open –> Database –> Please give Apps user credentials. It usually takes time to load all the workflows.
Select Standard from the list of workflows and press OK button.
When the WFSTD is Loaded then save on your desktop as STANDARD.wft:
Right click on Standard and create a new Item Type
The Item Type Internal name can have at the max of 8 Characters:
There are 3 types of Persistence’s as Temporary, Permanent and Synchronization.
The access levels are important to modify the workflow and can be set at workflow builder help.
Click OK
Now save the Workflow file as XAOATEST.wft on your local desktop:
Once a new Item Type is created then a new process needs to be created where the logic needs to go in:
We need to create a new Runnable Process so that we can call it from PLSQL/Form/OAF/Java. Under a Process there can be any number of sub process depending upon the complexity of the workflow logic that needs to be implemented.
Once the Process is created then we need to design the Process:
To Design any Process in Workflow it should start with One start Function and we get it from WFSTD. Just we need to drag and drop the start and end functions from theStandard Functions:
Even when we import the Start function go to its properties and we need to mention it should be a start:
Note: Any Process can have only one Start but can have any number of ends depending upon the Business logic’s complexity.
Similarly change the properties of the end function:
Click on OK button.
Now we need to create a Custom Function that has the business logic. You can have the Function call your plsql function or Java Class or any external application. We can mention the PLSQL Function Name in the Function Name field in the properties of the Function.
We can mention the result type if any Result is returned from the plsql Function:
Click OK.
Once the function is created just drag and drop the function between START and END Functions. Once the Function is placed just by using right click of the mouse draw the Flow how the process to be. Always The Process would be starting from Start and No Functions can be in the Process without coupling to another in the flow. Always the flow should end using and END function.
Now Verify the workflow and save in the data base or the (desktop and upload using wfload).
Once the workflow is saved in the data base which usually takes time we can test it using below queries:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
SELECT *
FROM wf_item_types
WHERE name = 'XAOATEST';
Result:
NAME PROTECT_LEVEL CUSTOM_LEVEL WF_SELECTOR READ_ROLE WRITE_ROLE EXECUTE_ROLE PERSISTENCE_TYPE PERSISTENCE_DAYS SECURITY_GROUP_ID NUM_ACTIVE NUM_ERROR NUM_DEFER NUM_SUSPEND NUM_COMPLETE NUM_PURGEABLE
XAOATEST 1000 0 TEMP 0
SELECT *
FROM WF_PROCESS_ACTIVITIES
WHERE process_item_type = 'XAOATEST';
Result:
PROCESS_ITEM_TYPE PROCESS_NAME PROCESS_VERSION ACTIVITY_ITEM_TYPE ACTIVITY_NAME INSTANCE_ID INSTANCE_LABEL PERFORM_ROLE_TYPE PROTECT_LEVEL CUSTOM_LEVEL START_END DEFAULT_RESULT ICON_GEOMETRY PERFORM_ROLE USER_COMMENT SECURITY_GROUP_ID
XAOATEST AOAMAIN_PROCESS 1 WFSTD START 803292 START CONSTANT 0 0 START -560,-160
XAOATEST AOAMAIN_PROCESS 1 WFSTD END 803294 END CONSTANT 0 0 END -208,-160
XAOATEST AOAMAIN_PROCESS 1 XAOATEST XXAOA_TEST_WF_FUNC 803296 XXAOA_TEST_WF_FUNC CONSTANT 0 0 -400,-160
XAOATEST ROOT 1 XAOATEST AOAMAIN_PROCESS 803291 AOAMAIN_PROCESS CONSTANT 1000 0
|
The data in WF_PROCESS_ACTIVITIES table explains the complete details of the workflow item type. Like how many Process, Functions, etc. with its versions.
PL/SQL code for this workflow:
PLSQL Package used in XAOATEST Workflow:
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
|
CREATE OR REPLACE PACKAGE 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
);
PROCEDURE LAUNCH_WORKFLOW ( itemtype IN VARCHAR2,
itemkey IN VARCHAR2,
process IN VARCHAR2
);
END XXAOA_TEST_WF_PKG;
/
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);
resultout := 'Success';
EXCEPTION
WHEN OTHERS
THEN
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
);
WF_ENGINE.STARTPROCESS ( itemtype,
itemkey
);
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.PUT_LINE('Error at LAUNCH_WORKFLOW: '||SQLERRM);
END LAUNCH_WORKFLOW;
END XXAOA_TEST_WF_PKG;
/
|
Sample Script to Kickoff or Trigger the workflow:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
DECLARE
lvItemType VARCHAR2(80) := 'XAOATEST';
lvUserId NUMBER := -1;
lvItemKey VARCHAR2(10);
vErrorMsg VARCHAR2(2000);
vErrorCode NUMBER;
BEGIN
lvItemKey := 'XAOA-01'; -- This should be unique value
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;
/
|
Script to test the Workflow statuses:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
SELECT *
FROM wf_items
WHERE item_type = 'XAOATEST';
Result:
ITEM_TYPE ITEM_KEY ROOT_ACTIVITY ROOT_ACTIVITY_VERSION OWNER_ROLE PARENT_ITEM_TYPE PARENT_ITEM_KEY PARENT_CONTEXT BEGIN_DATE END_DATE USER_KEY HA_MIGRATION_FLAG SECURITY_GROUP_ID
XAOATEST XAOA-01 AOAMAIN_PROCESS 1 08-JUN-13
SELECT *
FROM wf_item_activities_history_v
WHERE item_type = 'XAOATEST';
Result:
ITEM_TYPE ITEM_KEY ACTIVITY_DEF_BEGIN_DATE ACTIVITY_DEF_END_DATE BEGIN_DATE END_DATE EXECUTION_TIME BEGIN_DATE_TIME DURATION ACTIVITY_ITEM_TYPE ACTIVITY_TYPE PARENT_ACTIVITY_NAME ACTIVITY_NAME ACTIVITY_DISPLAY_NAME PARENT_DISPLAY_NAME ACTIVITY_STATUS NOTIFICATION_STATUS NOTIFICATION_ID RECIPIENT_ROLE RECIPIENT_ROLE_NAME ACTIVITY_STATUS_DISPLAY RESULT
XAOATEST XAOA-01 08-JUN-13 08-JUN-13 1 08-JUN-13 11:25:12 162 XAOATEST PROCESS ROOT AOAMAIN_PROCESS All Oracle Apps Main Process All Oracle Apps Test ACTIVE WF_ENGINE Workflow Engine Active
|
If you are running this Script outside of Oracle Applications like Running from any Oracle IDE then run the Workflow Background Process for your Item type to save time to Kickoff the workflow.
No comments:
Post a Comment