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.
Iterate The SharePoint List Item And Send A Consolidated Email To The Recipient Using Designer Workflow
Let's give it the name “Send_Email” and select the platform as “SharePoint 2013".
Iterate The SharePoint List Item And Send A Consolidated Email To The Recipient Using Designer Workflow
Once we've entered the Edit mode, click Local Variable from the ribbon and create some basic local variables.
Iterate The SharePoint List Item And Send A Consolidated Email To The Recipient Using Designer Workflow
The variables are -
Variable Name Type
 Index Integer
 RequestHeader Dictionary
 ResponseContent Dictionary
 ItemCollection Dictionary
 SiteURL String

Iterate The SharePoint List Item And Send A Consolidated Email To The Recipient Using Designer Workflow

Step 1
As a first step, log the information in the workflow history to know that workflow is started.
Step 2
Set a variable called Index as 0.
Step 3
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.

Name Type Value
 Accept String application/json;odata=verbose
 Content-Type String application/json;odata=verbose

Iterate The SharePoint List Item And Send A Consolidated Email To The Recipient Using Designer Workflow

Iterate The SharePoint List Item And Send A Consolidated Email To The Recipient Using Designer Workflow

Step 4
Get the current site URL and assign it to an already declared variable called Site URL.

Iterate The SharePoint List Item And Send A Consolidated Email To The Recipient Using Designer Workflow



Step 5
Call the HTTP web service and declare the REST API syntax to get the items.
Iterate The SharePoint List Item And Send A Consolidated Email To The Recipient Using Designer Workflow

Then, click on the properties of the called HTTP Web Service and declare the dictionary on a respective place.
Iterate The SharePoint List Item And Send A Consolidated Email To The Recipient Using Designer Workflow

Iterate The SharePoint List Item And Send A Consolidated Email To The Recipient Using Designer Workflow


Step 6
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.
Step 7
Get a result from the response content and store those values to the itemCollection variable.
Step 8
Count the number of items gotten from the item collection variable and store it in another variable called Count.
Step 9
You can log the count in Workflow History if required.
Step 10
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.
Iterate The SharePoint List Item And Send A Consolidated Email To The Recipient Using Designer Workflow


Step 11
Create a loop with times and add the count variable to run a number of times.
Step 12
Get a first column value by assigning ([%Variable:Index%])/CoumnName from ItemCollection Dictionary and output to a new variable.
Step 13
Repeat the step12 for all your columns.
Step 14
Set the variable that you created on step 10 and declare all column values here.

Iterate The SharePoint List Item And Send A Consolidated Email To The Recipient Using Designer Workflow

Step 15
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.
Step 16
Set the calculated calc value to the Index to get another list item.
Step 17
At last, send an email function with the collected items.

Iterate The SharePoint List Item And Send A Consolidated Email To The Recipient Using Designer Workflow

And the full workflow would be like the below image.

Iterate The SharePoint List Item And Send A Consolidated Email To The Recipient Using Designer Workflow

And the final result would be like below.

Iterate The SharePoint List Item And Send A Consolidated Email To The Recipient Using Designer Workflow

No comments:

Post a Comment