Use Power Automate to build an email recipient list and sending in Outlook vs Dynamics connector
Have you been wondering how you can build a dynamic list of email addresses that can be used to generate a new email? Below, we will take a look at how to build this list using Power Automate. We will also look at how to send this list using the Outlook connector and will then compare this with sending an email directly from Dynamics using the Common Data Service(Current Environment) connector.
Let's get started.
First, choose whichever trigger is necessary for generating the email recipient list. For this walk-through, I am simply using a recurrence trigger so that I can trigger it manually.
Once you have your trigger specified, you want to choose the Initialize Variable action for your recipients list, which will be built as an array
You can get your list of recipients from any data source available, but in this case, I am building a list of the top 5 Contacts that have an email address for demonstration purposes. This is using the Common Data Service (Current Environment) connector. To keep this simple, I am returning the top 5 Contacts where the Email Address field is NOT NULL.
You will need to iterate through each Contact record by choosing the Apply to Each action. Within the Apply to Each action, add the Append to array variable action to add the email address value to the array. In this case, I pull in the emailaddress1 using dynamics values from the returned Contact records.
Outside of the Apply to each loop, you need to join all of the array values with a semicolon. Select the Join variable action. Specify the outputs of the array values and enter a semicolon to join the values.
You can run the current configuration to test your results. When you look at the results of Join, you will see the following
You will see the inputs of the array and the outputs into a string of email addresses.
To send this using the Outlook connector, select Send an email (v2) action. Specify the Output of the Join function in the recipients line
After you send, you will see the recipients listed and sent successfully.
Now, if you want to achieve the same thing, but send directly from Dynamics, you will run into some complications. Dynamically building a list of recipients and adding to an email like we did in the Outlook connector, is not yet possible. Let's take a look.
Below, I have selected Create a new record using the Common Data Service (Current Environment) connector. For the entity name, select Email Messages.
As you can see below, you must individually specify each recipient value. Meaning, you would need to know the entity type and number of recipients. It requires the format as /entitylogicalname(recordid) in the Activity Party Attribute field. Unfortunately, you cannot specify multiple values in a string like we do with Outlook. There is a product enhancement suggestion to vote on here. Ability to dynamically build recipient list for Create Email Message in CDS (current environment) action
You can also use the following syntax /entityname/<GUID>
Stay tuned for the next post on creating and sending an Email from Dynamics using Power Automate.
Aaron Richards
Comments
-
Hi Aaron, Thank you for your post. About sending an email with the Common Data Service connector, there is a workaround that I tried it. There is a small button "switch to input entire array" that lets us put the entire array. In this way, we can build that array similar to what you explained, but we have to create every array item in a way that the connector understands it. It is a kind of hard code, but it works and solved my requirement for now. For understanding how we should create every array item, I used the results of my Power Automate flow, and used it to make the same array item. For example, if the activity party type is a user, here is what array I used to send email to two different users: (I removed the real ids because of security reasons). [ { "participationtypemask": 2, "partyid@odata.bind": "/systemusers/00000000-0000-0000-0000-000000000000" }, { "participationtypemask": 2, "partyid@odata.bind": "/systemusers/00000000-0000-0000-0000-000000000000" } ]
-
Earlier, we looked at building out a dynamics recipient list for a new Email and how you can use that in the Outlook connector vs the challenges with doing the same thing in the Common Data Service (C...
*This post is locked for comments