Use Contact Group’s List of Contact Emails for Notification

Jacob Reyes asked on June 5, 2018 00:18

Greetings,

Is it possible to create a macro expression that gets the list of contact emails from a specific Contact Group? Then use that list of emails for the Recipient field in the Email Notification in an online form?

An example would be a contact group called, “GreatLakeBusinesses,” that has a few contacts. I’d like to take those contact emails and use them as part of the notification.

So far the GlobalObjects.Contacts shows me a list of contacts, which allows me to get just one email from a contact, but not the list I’d like. I tried GlobalObjects.ContactGroups.GreatLakeBusinesses, but that doesn’t appear to be the right way to go.

Any advice in the right direction would be appreciated.

Correct Answer

Peter Mogilnitski answered on June 5, 2018 03:45

Yes it is possible, GlobalObjects.ContactGroups is just enumeration to give you info about existing groups on your site. You have to filter contacts: {%GlobalObjects.Contacts.Filter(ContactGroups.Exists(CodeName == "ContactGroupCodeName"))#%}

So to get emails (comma separated?) :

{%GlobalObjects.Contacts.Filter(ContactGroups.Exists(CodeName == "ContactGroupCodeName")).Columns("ContactEmail").Transform("{#ContactEmail#},").TrimEnd(",")#%}

P.S. There is an actual property of a contact .IsInContactGroup it works on a contact: {%GlobalObjects.Contacts.FirstItem.IsInContactGroup("ContactGroupCodeName")%}, but for some reason IsInContactGroup does not work with Filter: {%GlobalObjects.Contacts.Filter(IsInContactGroup("MyContactGroup"))#%}

Macros sometimes get tricky, but you can use system -> Macro -> Console and take a look as well at On-line marketing macros

1 votesVote for this answer Unmark Correct answer

Recent Answers


Jacob Reyes answered on June 5, 2018 17:12

Hi Peter Mogilnitski,

Now that I can see the properties being used in your expression, it makes a little more sense to me. The filter property was exactly the right way to go.

P.S. I've been using the Macro Console a lot more, but my JS background to K# feels like a steep learning curve.

Thank you again for the advice.

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on June 6, 2018 14:15 (last edited on June 6, 2018 14:17)

It will take some times to master macros :)

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.