Written by

Gokul Paranjothy

Share

  

Category

see all categories
intranet as a service

Getting SharePoint Group Users’ Email Addresses in SharePoint Designer Workflow

As SharePoint developers, we are often delegated the task of sending email notifications in a workflow process. In most of the cases, the email recipients are fetched from “User” type fields in a SharePoint List. In such scenarios, it is a straight forward approach to send emails, as the SharePoint designer workflow can retrieve the email address from the “User” type field and “Send Email” action is available to send out emails.

Unlike the usual scenario, there is sometimes a requirement where email notifications should be sent to all the members of a SharePoint User Group. This becomes a little bit tricky, as the “Send Email” action doesn’t have an in-built function to send email to all the members of a SharePoint group.

So, the objective here is to fetch all the users in the targeted SP group and hence their email addresses. When we searched in the internet, we realised that we can make SharePoint REST API calls from SharePoint designer workflows using “Call HTTP Service” action. And therein lies our solution, as we already knew the REST API code to fetch users from a SharePoint group.

$.ajax({  

        async: true,

        url: "http://<SiteUrl>/_api/web/sitegroups/GetByName('<GroupName>')/users",  

        method: "GET", 

        headers: { 

            "accept": "application/json;odata=verbose",  

            "content-type": "application/json;odata=verbose"    

        }, 

        success: function(data, status) { 

        },

        error: function (xhr, status, error) {

        }

})

Now we should convert the above syntax into a HTTP Service action. To do that, please follow the below stepsStart WF development 

Start WF development

Set Workflow variable “resetServiceUrl” (of type string) pointing to REST API endpoint using the string builder

Set Variable “Index” (of type Integer) to 0

Build dictionary with two entries, Accept and Content-Type, both having values “application/json;odata=verbose” and output it “responseHeaders

Step 2 :

Add a new stage and include “Call HTTP Service” action. Configure the stage actions as shown below. 

We must set only two parameters “URL” and “Response Header” in “Call HTTP Service” action, with the workflow variables we created in the first step.

 

If you have any comments/queries, please post it in this blog. Cheers 😊

Gokul Paranjothy

Written by Gokul Paranjothy

I am Senior SharePoint developer @ Hubfly Software Technologies. I am passionate about learning SPO and participating in community blogs.