You are here

You are here

Querying Workflow Status and Information

In some integration scenarios it can be useful to query the state of a running workflow.  Since the workflow's Id is needed in order to query it's status, querying the state of a workflow is almost always used in conjunction with one of the two BPMInitiateWorkflow methods.  At a high level, this equates to kicking off a workflow batch job in SpringCM, polling for it to complete, and then optionally pass data back from the workflow to the web services client.  Implementing this would be as follows:

  1. A workflow is initiated with either the BPMInitiateWorkflow or BPMInitiateWorkflowWithDocuments method.  The workflow's Uid is passed back in response which is subsequently used to query the workflow's state.  Note that SpringCM workflows have both a Uid (GUID) and a friendlier all numeric unique identifier that is seen in the workflow Process Monitor.  Either can be used to check the status of a workflow and will return identical information.
  2. The resulting workflow Id can be used to get the instance information from a workflow by calling the BPMWorkflowInstanceInformation method.  An SCMInstance object is returned and includes the Id,Name, Status, data in the information column, and start and end dates of the workflow instance.  Note that if this method is called directly after the workflow initiation is requested, it is possible that workflow execution may be queued for a short a period of time.  While the workflow is queued, the BPMWorkflowInstanceInformation may return no information or an exception.  It is for this reason a retry should be used when calling this method as shown in the examples below.
  3. The client code may continue to poll the BPMWorkflowInstanceInformation method until the workflow is "Completed".  In the case where the workflow is designed to pass information back to the web services client, the workflow can be designed to update its "Information" with data that can then be read by the web services client.
  4. Even if data does not need to be passed back, these methods can still be used to make sure that an initiated workflow executes successfully.

Vertical Tabs

c#
public static void GetWorkflowInstanceInformation(SpringCMServiceSoapClient springCMService, string token, string instanceId)
{
	var retry = 0;
 
	while (true)
	{
		retry++;
		try
		{
			SCMInstance workflowInstance = springCMService.BPMWorkflowInstanceInformation(token, instanceId);
			Console.WriteLine("Workflow with Id {0}, has status {1} and information {2}", workflowInstance.WorkflowId, workflowInstance.Status, workflowInstance.Information);
			break;
		}
		catch (Exception ex)
		{
			Console.WriteLine("Got the following error checking for workflow instance {0} will try again in 20 seconds.  Error: {1}", instanceId, ex.Message);
			if (retry < 7)
			{
				Thread.Sleep(20000);
			}
			else
			{
				throw new ApplicationException("Could not check status after 2 minutes", ex);
			}
		}
	}
}
java
public static void GetWorkflowInstanceInformation(SpringCMServiceSoapProxy springCMService, String token, String instanceId) throws Exception
{
	int retry = 0;
 
	while (true)
	{
		retry++;
		try
		{
			SCMInstance workflowInstance = springCMService.BPMWorkflowInstanceInformation(token, instanceId);
			System.out.format("Workflow with Id %s, has status %s and information %s", workflowInstance.getWorkflowId(), workflowInstance.getStatus(), workflowInstance.getInformation());
			break;
		}
		catch (Exception ex)
		{
			System.out.format("Got the following error checking for workflow instance %s will try again in 20 seconds.  Error: %s", instanceId, ex.getMessage());
			if (retry < 7)
			{
				Thread.sleep(20000);
			}
			else
			{
				throw new Exception("Could not check status after 2 minutes", ex);
			}
		}
	}
}