Introduction


This article describes how to iterate through results obtained from REST API call using Loop in SharePoint 2013 Designer Workflow.



Scenario


There is a list "Users" which hold information about users in a team with two important columns: "Active Status" and "User Name". This column accepts Yes or No and identifies which users are active on that team. There is one more list, "Project Tasks", which holds tasks assigned to users. Multiple tasks can be assigned to users. This list also has one column "Active" which corresponds to the "Active Status" column in "Users" list. So, whenever a user's Active status is changed, some status should be updated for all occurrences of that user in the "Project Tasks" list. The reason for this setup? While generating a report of assigned tasks, admin/superuser wants to see tasks only for the active users.

Users



Project Tasks





Implementation


Create a List workflow on "Users" list and set it to run automatically on item change. Follow below steps-

Set workflow variable (URL) 





Build a dictionary and rename variable to "requestHeaders". Add items below to dictionary:
  1. Name: Accept, Type: String. Value: application/json;odata=verbose
  2. Name: Content-Type, Type: String. Value: application/json;odata=verbose


Call HTTP Web Service. Click on "this" -> set variable "URL" as HTTP Web Service URL and select "HTTP GET" as method. Open action properties and set "RequestHeaders" value to variable "requestHeaders" created in earlier step. Click on "response" and select "create new variable". Create a variable of type dictionary and name as "responseContent".




Get items from the dictionary and output to variable "list".



Count items in the dictionary and output to variable "count".




Now, add an If condition to check if the count is greater than 0. If yes, add a Loop with Condition action. Set a variable "index" (Integer) to "0". 

Add a Get Items action to get UserId from "responseContent" dictionary and update status with Current Item status in Project Tasks list.

Increment the index using calculation action.




Hope it helps