Complete a Task using Invoke Web Service Activity
Sometimes, you may wish to have a Process complete a Task that has been previously generated by a second Process.
For example, a Customer sends an e-mail to the Bluespring Support mailbox, initiating a Process which generates two items: a Ticket to track all information associated with the Customer's question and a specific Manual Task to prompt the Support personnel to answer the Customer's question. Later, the Ticket is marked as having been Resolved, which initiates a second Process that will complete the Manual Task.
How do you ensure this second, seemingly unrelated Process (initiated by resolving the Ticket) completes the Manual Task? By using the Task Key within the Assign Task Activity as an identifier associated with the Ticket itself. When the Ticket is updated and initiates a new Process, you can use the Invoke Web Service Activity to call the Tasks Service and find the Manual Task by the Key. You then use a second Invoke Web Service Activity to update the status of the Manual Task to Completed (Successful).
To continue our example, set the Task Key to the value of the Ticket Number. Then, when the Process initiates because the Ticket has been Resolved, you can identify the Task based upon the value of the Task Key. First, we must call the BPM Task Service. In the screen shot below, the value of the Task Service's Web Service Definition Language (WSDL) has been determined in a Data Item. Specifically, we use the GetTasks Method in the Task Service.
Within the Input Parameters, we map the Data Item containing our identifier to the parameter: Key, so we only return those Tasks which have the correct value for the Key. In the example below, we return only those Tasks where the Key equals the Ticket ID of our Support Ticket:
Lastly, within the Output Parameters, we map the entire XML returned from the Task Service to a new Data Item.
We can then update the Task's XML before using it as an input to our second Invoke Web Service Activity. We use the entire XML as it will allow us to change the state of the Task from "Waiting (Assigned)" to "Completed (Successful)" as well as update any other attribute of the XML we wish, such as the AssignedTo field to accurately reflect the person who set the Ticket to Resolved.
Once we have the entire XML, we can update State within it, from 202 to 302, i.e. from Waiting (Assigned) to Completed (Successful), as per the
Activity Instance States, using an Expression:
Replace(Process.DataItems.TicketXML, ">202</ID> <State xmlns=", ">302</ID> <State xmlns=").
Finally, we use a second Invoke Web Service Activity, configured to use the SaveTask Method with our updated XML mapped to the Parameter: task. In the screen shot below, the Task's updated XML (using the Expression to replace the State's ID element) has been saved as the TicketXMLCompleted Data Item:
And now we have configured a second Process to update a Task generated within another Process!