How To: Configure and use the "Wait for External System" option in a workflow

This topic shows you how to configure and use the Wait for external system option in a SmartObject workflow event.

The Wait for external system option (sometimes also referred to as an asynchronous server event) provides a way of pausing a workflow and waiting for an external application to finish doing something. Essentially, it is like assigning a task to a system, and the workflow will wait for that system to finish its work before continuing. External events are sometimes unpredictable in terms of how long they might take to complete, and by using this option, you can configure your workflow event to wait until the external system confirms that it is finished. Your workflow will not continue on to the next workflow step until the event completes. The external event in this example uses the workflow REST API to communicate with K2, but you can also use the workflow client API.

You can use REST and Client API in K2 Five, but in K2 Cloud you can only use the REST API. You may require a developer that is familiar with the external system who can write the code necessary to call back to K2.

To configure this feature in the workflow, check the Wait for external system check box in the Options section of the configuration panel on a SmartObject step. You will use the SmartObject input mappings to pass the unique workflow step serial number (SN) to the external system. The external system needs to use this Serial Number to connect back to K2 and tell K2 which workflow instance to carry on with. The external system can also use the SN to open the workflow and set workflow variables values, before telling K2 to complete the SmartObject event.

As an example, you might have a sales order process, where the workflow calls an external service to place an order. The external service can take hours to complete their part of the order request before sending back a confirmation. It would be inefficient to poll the external system to determine if the order is processed; the "Wait for External System" option would be more efficient. You would configure the Wait for external system option on the SmartObject that represents the external service, which pauses the workflow until the external system confirms the order is processed by calling back to the K2 server with the serial number. The Sales Order workflow continues once it has received confirmation from the external system that the order was processed.

Configuring the "Wait for External System" option

Using the Wait for External System Option

To help you learn how to use the Wait for External System option, you can follow the steps below that describe how to implement a sample scenario. You can either build out the solution from scratch, or download and deploy the sample project described by these steps.

This sample project consists out of a SmartObject, workflow, external app and external code (REST API / Client API). Click here to download the WaitForExternalSystemSample.zip solution. The solution includes the following:

You can follow Part 1, 2 and 3 below to build out the solution yourself, or alternatively you can download the WaitForExternalSystemSample.zip solution. After downloading the solution, deploy the K2 package to your environment, enable the REST API, and then continue from Part 4 to test the solution. (This sample solution is based on the standard K2 Denallix environment, so you might need to edit the application's configuration file or edit the sample code for it to work in your environment.)

Steps