A workflow can be initiated from PL/SQL using 2 methods,
LaunchProcess and StartProcess.
Launch Process
CREATE OR REPLACE PACKAGE launchwflow_pkg
AS
PROCEDURE launchwf;
END launchwflow_pkg;
/
CREATE OR REPLACE PACKAGE BODY launchwflow_pkg
AS
PROCEDURE launchwf
IS
l_wfsequence NUMBER;
BEGIN
l_wfsequence := '123456';
-- Kick off the workflow
wf_engine.launchprocess (itemtype => '<item_type>',
itemkey => l_wfsequence,
process => '<process_name>',
userkey => 'XX-'||l_wfsequence,
owner => 'SYSADMIN'
);
COMMIT;
RETURN;
END launchwf;
END launchwflow_pkg;
/
Start Process
CREATE OR REPLACE PACKAGE BODY wflowproc
AS
PROCEDURE start_test_wf
IS
ret_stat NUMBER;
l_wfsequence NUMBER;
l_itemtype VARCHAR2 (40);
l_process VARCHAR2 (40);
l_userkey VARCHAR2 (40);
l_owner VARCHAR2 (40);
l_parent_itemtype VARCHAR2 (40);
l_parent_itemkey VARCHAR2 (40);
BEGIN
l_itemtype := 'TEST_WF';
l_process := 'TEST_PROCESS';
l_userkey := 'ABCD1234';
l_owner := 'SYSADMIN';
l_wfsequence := '12345';
-- Create the workflow process instance
wf_engine.createprocess (itemtype => l_itemtype,
itemkey => l_wfsequence,
process => l_process,
user_key => NULL,
owner_role => NULL
);
-- Set the user key of the workflow (the user key can be set in the
-- CreateProcess step also. Then this step will not be required)
wf_engine.setitemuserkey (itemtype => l_itemtype,
itemkey => l_wfsequence,
userkey => l_userkey
);
-- Set the workflow item owner
wf_engine.setitemowner (itemtype => l_itemtype,
itemkey => l_wfsequence,
owner => l_owner
);
-- Set the initial values for the attributes
wf_engine.setitemattrtext (itemtype => l_itemtype,
itemkey => l_wfsequence,
aname => 'REQUESTOR',
avalue => 'OPERATIONS'
);
wf_engine.setitemattrtext (itemtype => l_itemtype,
itemkey => l_wfsequence,
aname => 'APPROVER',
avalue => 'MANAGER'
);
-- If the workflow we are about to execute is going to be a child process
-- for another workflow then we need to connect the running parent process
wf_engine.setitemparent (itemtype => l_itemtype,
itemkey => l_wfsequence,
parent_itemtype => l_parent_itemtype,
parent_itemkey => l_parent_itemkey,
parent_context => NULL
);
-- Kick off the workflow
wf_engine.startprocess (itemtype => l_itemtype,
itemkey => l_wfsequence);
COMMIT;
END start_test_wf;
END wflowproc;
/
No comments:
Post a Comment