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:

  save_threshold := wf_engine.threshold;
  wf_engine.threshold := -1;
  wf_engine.threshold := save_threshold;
  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

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.

By continuing to use the site, you agree to the use of cookies. more information

In common with almost all professionally run websites, this website logs the IP address of each visitor in order to keep it running reliably. This is also essential for protecting the website and its visitors from malicious attacks, including infection with malware.

This website provides information as a service to visitors such as yourself, and to do this reliably and efficiently, it sometimes places small amounts of information on your computer or device (e.g. mobile phone). This includes small files known as cookies. The cookies stored by this website cannot be used to identify you personally.

We use cookies to understand what pages and information visitors find useful, and to detect problems such as broken links, or pages which are taking a long time to load.

We sometimes use cookies to remember a choice you make on one page, when you have moved to another page if that information can be used to make the website work better. For example:
- avoiding the need to ask for the same information several times during a session (e.g. when filling in forms), or
- remembering that you have logged in, so that you don’t have to re-enter your username and password on every page.

You can prevent the setting of cookies by adjusting the settings on your browser (see your browser Help for how to do this). Be aware that disabling cookies will affect the functionality of this and many other websites that you visit.