Sharepoint migration

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 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 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 doesnt 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.