Print Post Launching Workflow from a Trigger

There are certain situations when you may need to launch a workflow from a trigger, which is supported but in a restricted manner. Whenever a workflow activity starts, a savepoint is issued – which is not allowed in a trigger, so if you need to launch your flow (or restart it) from a trigger, you need to ensure that the code doesn’t get as far as issuing a savepoint by deferring it to the background.

In order to determine whether the activity should run in the foreground or the background, the workflow engine checks an externalized constant called WF_ENGINE.THRESHOLD. If the cost of the activity in the workflow is above the threshold, then the activity is deferred to the background and you need to run a background engine to execute it.

In order to force the engine to defer the thread, you need to set the threshold to a value which is going to be lower than the cost of the activity, and then communicate witht= the workflow engine. Once you have called the engine, you MUST ensure that you set the threshold back, or all workflow activities from that point on will defer to the background.

Once you’ve deferred the thread, run a background engine (WF_ENGINE.BACKGROUND or there is a seeded concurrent program in eBS) to start the process moving again. Here’s the code to do it:

begin
  save_threshold := wf_engine.threshold;
  wf_engine.threshold := -1;
  wf_engine.createprocess('<ItemType>','<ItemKey>','<Process>');
  wf_engine.startprocess('<ItemType>','<ItemKey>');
  wf_engine.threshold := save_threshold;
exception
  when others then
  -- remember to reset the threshold
  if wf_engine.threshold <= 0 then
    wf_engine.threshold := save_threshold;
  end if;
  -- continue with normal error handling
end;

This works fine if you are using the CreateProcess and StartProcess (or LaunchProcess) APIs, but doesn’t work for raising a business event. The next post will look at the only way that you can raise a business event from a trigger.

This entry was posted on Sunday, August 17th, 2008 at 9:47 pm and is filed under Oracle, Technical. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

« What’s the best way to archive Workflow data?
Launching Workflow from a Trigger – Part 2 »

Leave a Reply

  • Pages

    • About Us
    • Services From WorkflowFAQ
    • Training
    • Workflow Book
    • Careers
    • Forum
    • Blog
  • Oracle 11i Workflow Certified Expert
    Oracle 11i System Administrator Certified Expert

  • Search


  • Blog

    Archives

    • January 2012
    • November 2011
    • October 2011
    • September 2011
    • August 2011
    • July 2011
    • June 2011
    • April 2011
    • February 2011
    • January 2011
    • December 2010
    • October 2010
    • September 2010
    • April 2010
    • March 2010
    • February 2010
    • January 2010
    • December 2009
    • October 2009
    • August 2009
    • July 2009
    • March 2009
    • February 2009
    • January 2009
    • December 2008
    • November 2008
    • October 2008
    • September 2008
    • August 2008
    • July 2008
    • June 2008
    • May 2008
  • Categories

    • General Computing (30)
    • Non-Oracle (18)
    • Oracle (77)
      • Functional (20)
      • Technical (68)
    • Personal (2)

  • Links

  • General Computing

    • Computing Magazine
    • Download.com
    • SourceForge.net
    • The Daily WTF
    • The Register
  • Non-Computing

    • BBC News
    • Burnley-based professional photography
    • Cuteable
    • My wife’s shop
  • Oracle Related

    • AppsDBA
    • Oracle
    • Oracle Apps Blog
    • Oracle Magazine Interactive
    • Oracle Support
    • Oracle Technology Network
    • Oracle UK
    • Oracle Workflow Forum on OTN
    • Oracle WTF
    • OraFAQ
    • Steven Chan
    • Steven Feuerstein


Copyright © 2012 TS Fifteen Ltd. All rights reserved.