SharePoint Designer 2013 Workflows – How to get Task Process ID

A recent project needed several task management workflows, which meant exploring the pros and cons of each option in SharePoint designer.

Using the “Start Task Process” has the benefit of the workflow being aware of the outcome and “waiting” until the task process is complete. this means you can easily act upon the result, approve or reject, later on.

However you cannot easily get to the other task fields, or the ID, if you need to add extra data. The “Start Task Process” only returns the outcome as a variable but the biggest issue is that the workflow does not progress after this task has been created, it waits, so leaves no chance to update it before completion.

The solution
The workflow needs to perform some actions in parallel, sort of, and a “HTTP Web Service Action”.
The web service can get the ID of the latest Task by using the following URL

[%Workflow Context:Current Site URL%] /sites/mySite/_api/web/lists/getbytitle('tasks')/items?$top=1&$orderby=Id%20desc

Using this URL in a “Call HTTP web service” to return “ResponseContent”

The next action is get item from dictionary

Get d/results(0) from Variable: ResponseContent (Output to Variable: ResponseContent )

Following with this

Get Id from Variable: ResponseContent (Output to Variable: TaskId )

This can only work if the workflow runs in a parallel block but with a tweak to run slightly after – this ensures the task item is definitely there.

Setting up the call web service can be done in this way

Do the web service setup steps as normal then add a parallel block

Add and configure start task process into it

The following actions will run in parallel:
 Start a task process with Variable: Region (Task outcome to Variable: Outcome1 )

Then add an If block

If Current Item:ID is greater than 0

This allows a run of actions sequentially (but still in parallel to the task). Without this the next steps would all trigger at the same time.

Add a pause before continuing just to ensure the task IS created

 Pause for 0 days, 0 hours, 1 minutes

Then call the web service

Call [URL]... HTTP web service with request (ResponseContent to Variable: ResponseContent |ResponseHeaders to responseHeaders |ResponseStatusCode to Variable: responseCode1 )

Manage the results

Get d/results(0) from Variable: ResponseContent (Output to Variable: ResponseContent )
Get Id from Variable: ResponseContent (Output to Variable: TaskId )

You can then update an item in a list using the newly found TaskId

After that you can continue outside of the parallel block and wait for the task to be Completed.

4 thoughts on “SharePoint Designer 2013 Workflows – How to get Task Process ID

  1. Hello !

    Nice tutorial. However, what is happening when the task process is concerning multiple assignees ? Will you get the task ID for every of them ?

    Like

    • No, this method will only get the latest task created. If you ensured that all tasks created share something in common, perhaps a reference in part of the Task Title you could use this method to return one, pull the reference out and then make a second call to get all task with that reference. Only a couple more steps.

      Like

  2. Hi Ryan, I’m reading up on your documentation for this and it all makes sense But like the other user said, I have an taks process that will be assigned to multiple people. I only need to be able to get the rejector’s comments. How would I do that?

    Like

    • In the step where you create the tasks you need to include something useful that they will all share, like a reference you calculate with the workflow. Include this reference as part of the task title. Now instead of using
      “getbytitle(‘tasks’)/items?$top=1&$orderby=Id%20desc”
      you can use something like
      getbytitle(‘tasks’)/items?&$filter=substringof(‘REF’,Title)
      This will return a collection that will have to be managed to filter on only the one you want to return its data.

      Like

Leave a Reply to John Mizell Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.