Saturday, December 1, 2012

Launch workflow from PLSQL.



This procedure can be used to launch workflow from PLSQL.

PROCEDURE start_training_wf(p_po_id IN INTEGER) IS
    l_itemtype VARCHAR2(30) := 'XXXXPTR';
    l_itemkey  VARCHAR2(300) := 'TRAINING-' || p_po_id;
    CURSOR c_get IS
      SELECT *
      FROM   po_headers
      WHERE  po_id = p_po_id;
    p_get c_get%ROWTYPE;
  BEGIN
    OPEN c_get;
    FETCH c_get
      INTO p_get;
    CLOSE c_get;

    wf_engine.createprocess(l_itemtype, l_itemkey, 'MAIN_TRAINING_PROCESS');
 
    wf_engine.setitemuserkey(itemtype => l_itemtype
                            ,itemkey  => l_itemkey
                            ,userkey  => 'USERKEY: ' || l_itemkey);
    wf_engine.setitemowner(itemtype => l_itemtype
                          ,itemkey  => l_itemkey
                          ,owner    => 'SYSADMIN');
 
    wf_engine.setitemattrnumber(itemtype => l_itemtype
                               ,itemkey  => l_itemkey
                               ,aname    => 'PO_ID'
                               ,avalue   => p_po_id);

    wf_engine.setitemattrtext(itemtype => l_itemtype
                             ,itemkey  => l_itemkey
                             ,aname    => 'SEND_TO_EMAIL'
                             ,avalue   => p_get.send_email_to);
    wf_engine.setitemattrtext(itemtype => l_itemtype
                             ,itemkey  => l_itemkey
                             ,aname    => 'PO_DESCRIPTION'
                             ,avalue   => p_get.po_description);
    wf_engine.startprocess(l_itemtype, l_itemkey);
 
  END start_training_wf;

No comments:

Post a Comment