2 Email Group Members from a Workflow 4 Derek Mangrum posted 9 Years Ago I am working on creating some additional Facilities Requests for our Facilities teams to handle work orders. I have copied the provided Facilities Request Workflow and am making the needed changes. I have run into a need to have my Workflow send an email to the members of a group. The 'Send Email' action type lets you manually enter SMTP address(es) or reference an attribute value. It doesn't appear that you can target a Group and have emails sent to each group member. If there is an easy way, please let me (us, the community) know. Or, this could be a call/request for a 'Send Email to Group' Workflow Action. I have, however, created a workaround that I wanted to share. First, there are three Workflow Attributes that you will need. 1) an attribute to hold the Group you want to target, 2) an attribute to hold the raw email address list, 3) an attribute to hold the trimmed email address list. I found that, when manually entering email addresses in the 'Send Email' action, a comma-delimited list works for sending email to multiple recipients. This delimited list must be well-formed, though... no trailing commas, for example. I set the 'Worker Group' attribute default value to be the group that I will be sending email to in my workflow. I then have three actions that create and send the email to the group members. The first action is a 'Set Attribute Value' configured like this: As you can see, the magic happens thanks to the power of Lava! The full text of the "Text Value" field is: {% assign grp = Workflow | Attribute:'WorkerGroup','Object' %}{% for member in grp.Members %}{% if member.Person.IsEmailActive == true and member.GroupMemberStatus == 1 and member.Person.RecordStatusValue.Name != empty and member.Person.RecordStatusValue.Name != 'Inactive' and member.Person.Email != '' %}{{ member.Person.Email | Downcase }},{% endif %}{% endfor %} Briefly, this Lava assigns the WorkerGroup, as an object, to the 'grp' variable. Then, I loop through the .Members collection of that grp variable. For each 'member', I do various checks and then add the SMTP address followed by a comma. Once complete, this creates a string similar to 'email1@abc.com,email2@xyz.com,' and stores it in the Group Member Emails attribute. That trailing comma is a problem, so I have to get rid of it. The next action does that for me. Once again, Lava works well here. The full text is: {% assign valLength = Workflow.GroupMemberEmails | Size | Minus:1 %}{{ Workflow.GroupMemberEmails | Truncate:valLength,'' }} This just gets the length of the email list string, subtracts one, and truncates the string to that shorter length. It then stuffs this new string into the 'Group Member Emails Trimmed' workflow attribute. Lastly, I use the 'Send Email' action type and target my 'Group Member Emails Trimmed' attribute value for the 'Send To Email Address'.
Derek Mangrum 9 years ago I believe Version 4.0 will have this fixed. So, you will just be able to target a group and it will automatically send the email to all group members.
Derek Mangrum 9 years ago The 'Assign to Group' action doesn't have the ability to send a communication, as far as I can tell. I can (and do) assign Activities to Groups, but I need to be able to also send a notification email to all the group members.
Arran France 9 years ago I'm pretty sure you can email a group if they're assigned by using a User Entry Block.
Derek Mangrum 9 years ago Can you give more details on how you implemented this? I have an action that assigns an Activity to a Group, but I still don't see how to then send an email to all those group members. I would love to see how you are implementing that. I am getting lost on "User Entry Block" comment. I am not sure what that is and how it relates to Workflows/Activities/Actions. It sounds like you have a method that is much easier to implement than mine. I am eager to learn. Thank you!
Trey Hendon III 9 years ago Hey Derek,Line 152 (https://github.com/SparkDevNetwork/Rock/blob/07559604ee47d577f6f4de1eececaa61caae4697/Rock/Workflow/Action/SendEmail.cs) evaluates if the Attribute is a Group and gets all it's members to send an email.I really like this idea, though, and am trying similar (using SQL to build my Attribute string of comma separated emails). Unfortunately, though, for some reason, the emails aren't going out, while the Workflow Log shows successful. Did you have to do anything else in config to get the emails to work?-Trey
Trey Hendon III 9 years ago Sorry, should have clarified that more.For your case, you'll need an Attribute (a Group attribute) that gets set (or is defaulted to) the group you want to email.
Arran France 9 years ago Derek -What I did was use an 'User Entry' action which is simply a set of workflow attributes with some pre/post-HTML and then a command button which can trigger a new activity. The User Entry block can be configured to email a system email notification to a group that's assigned.For example, we're using this to assign newcomers to our visiting team. We're capturing data about the newcomer via SQL and storing it as workflow attributes (address, phone number), assigning the visiting team, and then the User Entry block is the next action. They get an email with the selected Workflow attributes (so we're showing them the name, address, and phone number but not some 'behind the scenes' attributes) and then a button at the bottom labelled 'Visited' to click which completes the workflow.The key part is the 'assign' action which is assigning the entire group which means the entire group is getting an email.Trey -What would be the advantage in a comma list versus a typical group?