Skip to content
2 min read

Email SharePoint Groups in Visual Studio Workflow - the easy way


For any of you who are familiar with Visual Studio workflows... you love the added flexibility but you also hate the Workflow Designer and sometimes the activities aren't very clear... Recently I had been working on a workflow for a ticketing system to send emails to members of a SharePoint group. By default, the Visual Studio Workflow Toolkit gives you several actions you can use to acheive this.


LookupSPGroup

Loads the properties of the SharePoint group into a dynamic value, based on the groups principle ID

LookupSPGroupMembers

Loads the members of a SharePoint group into a dynamic value, based on the groups principle ID

LookupSPPrincipal

Loads a set of properties for a SharePoint user or group value, based on the princpal name.

 

At first, you are probably thinking "let's use LookupSPGroupMembers because I would like to load each user and grab their e-mail from the Dynamic Values and add them to a collection". Here is a blog post that describes how to do this. This was my go-to method whenever I needed to get properties for a user within a SharePoint group. 

Then one day...it all changed! A co-worker of mine was working through another workflow and he showed me a much simpler approach to emailing a SharePoint group...by only using the group name! Every blog post I've found would always use the above approach and create a collection of user emails. Come to find out, the Email activity accepts email address, user id's and also user names...

This is when I switched to using the LookupSPGroup activity. By using the LookupSPGroup activity, I can pass this activity the principle id of my SharePoint group and grab the "Title" of the group and subsquently add the Title value to a collection for the Email Activity.

GrabTitle.png

 


The above activity is getting the dynamic value property for "Title" from the Group. The next step will be to take the new variable "GroupName" and add it to a collection.

AddToCollection.png

 The next step after adding the Title of the group to the "EmailCollection", you will drop an Email activity and use the "EmailCollection" as the "To" field. 


 Now you are probably thinking... Beau, that's still too complicated, can't I just add the Group Name to the collection via a string instead of using LookupSPGroup? The answer is YES! It is in fact true, if you do not want to use the PrincipleID of the group... but you wanted to just type the group name such as "Test Site Members" and add it to the collection variable, it would work! This would be okay if your group name never changes, but you should be aware that your workflow will not send out any emails if you change your group name after the fact.

Share
  
DON'T MISS!

Expert Insights from the Aerie Team

Drop us a line

Our team will be happy to answer your questions.

ADDRESS: 110 West Canal Street, Suite 201
Winooski, VT 05404

PHONE
: (813) 358-4656
HOURS: 8:00 am - 5:00 pm EST Monday to Friday
EMAIL: chanson@aerieconsulting.com