THIVAGAR SEGAR BLOG'S
SharePoint, SharePoint Online, Office 365, Azure, Powershell, Windows Server, SQL Server
Wednesday, August 28, 2019
Iterate SharePoint List Items And Send A Consolidated Email To a Recipient Using Designer Workflow
By default, there is no OOTB (Out-of-the-Box) workflow to send an email with a consolidated list item, so in SharePoint 2013, the Designer Workflow has a special feature called “Call REST API”.
So, I am using site workflow here, since we are going to iterate the list item.
Let's give it the name “Send_Email” and select the platform as “SharePoint 2013".
Once we've entered the Edit mode, click Local Variable from the ribbon and create some basic local variables.
The variables are -
As a first step, log the information in the workflow history to know that workflow is started.
Set a variable called Index as 0.
Build a dictionary to understand the code from the response. For that, we need to add two values to get the information from SharePoint and assign the output to the RequestHeader dictionary.
Get the current site URL and assign it to an already declared variable called Site URL.
Call the HTTP web service and declare the REST API syntax to get the items.
Then, click on the properties of the called HTTP Web Service and declare the dictionary on a respective place.
Log the response code in the Workflow history. If your REST API code works, then the response code would be OK or else, it will return as NOTOK.
Get a result from the response content and store those values to the itemCollection variable.
Count the number of items gotten from the item collection variable and store it in another variable called Count.
You can log the count in Workflow History if required.
Create a new variable to store all your looped items in one place. Here, I have created a variable called EmailContent and added some Table Header.
Create a loop with times and add the count variable to run a number of times.
Get a first column value by assigning ([%Variable:Index%])/CoumnName from ItemCollection Dictionary and output to a new variable.
Repeat the step12 for all your columns.
Set the variable that you created on step 10 and declare all column values here.
As a loop, we need to increase the index value with the value 1 because values return like array 0,1,2,3… so, calculate the index value plus 1 and store it in another variable called Calc.
Set the calculated calc value to the Index to get another list item.
At last, send an email function with the collected items.
And the full workflow would be like the below image.
And the final result would be like below.