After the workflow starts, the Web services client can perform various actions in response to events while the workflow is running.

Before you begin

You must have implemented operations in the Web service client to run workflows in the Orchestrator server.

Procedure

  1. Find running workflows by calling the getWorkflowTokenForId operation.

    Calling getWorkflowTokenForId obtains a WorkflowToken object, which contains all of the information about that specific workflow token.

    WorkflowToken onemoretoken = vsoWebControl.getWorkflowTokenForId(workflowTokenId, username, password);
    AllActiveWorkflowTokens[n] = onemoretoken;

    The preceding code example obtains a WorkflowToken object from its ID and sets it into an array of running WorkflowToken objects.

  2. Check the status of a workflow token by calling the getWorkFlowTokenStatus operation.

    When a workflow runs, an application's main event loop usually concentrates on checking the status of the workflow at regular intervals. The getWorkflowTokenStatus operation requires an array of the IDs of the workflow tokens for which it is obtaining the status.

    String workflowId = workflows[0].getId(); 
    WorkflowToken token = vsoWebControl.executeWorkflow(workflowId, username, password, null); 
    String[] tokenIds = { token.getId() }; 
    String tokenStatus = ""; 
    while ("completed".equals(tokenStatus) == false 
          && "failed".equals(tokenStatus) == false 
          && "canceled".equals(tokenStatus) == false 
          && "waiting".equals(tokenStatus) == false) { 
             Thread.sleep(1 * 1000); // Wait 1s 
             String[] status = vsoWebControl.getWorkflowTokenStatus(tokenIds, username, 
                      password);
             tokenStatus = status[0]; 
             System.out.println("Workflow is still running...(" + tokenStatus + ")"); 
    }
    

    The preceding example obtains the IDs of an array of workflow tokens. It checks the status of a WorkflowToken by calling getWorkflowTokenStatus().

    The preceding example keeps the application updated on the status of the WorkflowToken objects by checking their state at one second intervals. For example, If the workflow is in the waiting state, it is waiting for runtime input from the answerWorkflowInput operation.

  3. Provide inputs from user interactions by calling the answerWorkflowInput operation.

    If a workflow is waiting for user input in the waiting state, an application's event loop can specify that input at any time. You can create WorkflowTokenAttribute arrays as normal, and then supply them to a workflow during its run by using the answerWorkflowInput operation. The following example continues the code from 2.

     if ("waiting".equals(tokenStatus) == true) {
                    System.out.println("Answering user interaction");
                    WorkflowTokenAttribute[] attributes = new WorkflowTokenAttribute[2];
                    WorkflowTokenAttribute attribute = null;
                    attribute = new WorkflowTokenAttribute();
                    attribute.setName("param1");
                    attribute.setType("string");
                    attribute.setValue("answer1");
                    attributes[0] = attribute;
                    attribute = new WorkflowTokenAttribute();
                    attribute.setName("param2");
                    attribute.setType("number");
                    attribute.setValue("123");
                    attributes[1] = attribute;
                    vsoWebControl.answerWorkflowInput(token.getId(), attributes, username, 
                               password);
                }
    

    In the preceding example, if the workflow is in the waiting state, the application creates two WorkFlowTokenAttribute objects. The objects call the various WorkFlowTokenAttribute operations to obtain the attribute values. The process then adds these WorkFlowTokenAttribute objects into a WorkflowTokenAttribute array.

  4. Cancel a workflow by calling the cancelWorkflow operation.

    You can cancel a workflow at any time using the cancelWorkflow operation.

    vsoWebControl.cancelWorkflow(workflowTokenId, username, password);
  5. Check that the workflow canceled successfully.

    Because the cancelWorkflow operation does not return anything, you must obtain the WorkflowToken status to make sure the workflow canceled successfully, as the following code example shows.

    String[] status = vsoWebControl.getWorkflowTokenStatus(tokenIds, username, password);
    if ("canceled".equals(status) == true) {
       System.out.println("Workflow canceled");
    }

Results

The Web service client interacts with workflows by finding their status, supplying input parameters from user interactions, and by canceling the workflows.

What to do next

Implement operations in the Web services client to extract the workflow results.