Asynchronous workflow invocation using RestAPI

  • 22 March 2021
  • 1 reply
  • 27 views

Hi,

I have API service that starts k2 workflow. The call is synchronous i.e. Workflow API sends response after workflow is in active state ( process reaches Human task, Timer).

Is there any way to call Workflow API asynchronously ?

Thanks


1 reply

Userlevel 3
Badge +10
You can try using the workflow client api:
https://help.nintex.com/en-US/k2five/devref/5.4/default.htm#Runtime/WF-Client/Start_Instance.html

The StartProcessInstance method has an overload method that accepts a parameter called Sync.

This setting effectively determines how quickly K2 will respond with a success message after the workflow has started. If you start a workflow Synchronously (in other words, the Sync parameter’s value is True), K2 will not respond with a success message until the next wait-state in the workflow is reached. A wait-state could be something like an activity with a client event, or an activity with a start rule. Essentially, this parameter tells K2 to perform all the activities and events in the workflow until the workflow is waiting for something or someone. Only when this wait-state is reached will the method return to the calling application. When starting a workflow is this manner, you are ensured that all the intermediate workflow activities and events leading up to the wait state have been completed.

This Synchronous style of execution is mostly used in screen-flow applications or automated testing, because you want to be sure that the first client event is created before the StartProcessInstance call returns. When the call returns, you would normally search through the user’s worklist for the resulting task and then perform the next action, rather than polling the user's worklist several times and waiting for the task to appear.

In the majority of cases you will want to start a workflow asynchronously because you do not need to wait for activities or events to complete. This is also the default behavior, unless you specifically override by setting the Sync parameter to true, as shown in the following code snippet:

K2Conn.StartProcessInstance(K2Proc, true);

Starting workflows synchronously (Sync=true) is slower than starting workflows asynchronously (Sync=false), and you should not use the Synchronous-style execution unless there is a specific reason to do so.

Reply