Email Dynamics 365 team using Microsoft Flow
Views (561)
This week I had a requirement to send a daily email containing a list of open leads to different Dynamics teams based on the country of the lead. Rather than diving straight in writing a custom workflow activity to do so I thought I’d give it a go using Flow. Most of the steps were fairly self-explanatory but retrieving the team members to email required a bit of a workaround. Here’s how to do it:
-
- Create a schedule step
- Initialize a variable to store our team member email address in (more on why this is required later)
- Give this a suitable name and ensure it’s of type String
- Retrieve the Dynamics team using Dynamics 365 – List Records (Preview) step. Be sure to Show advanced options for this step. To retrieve team members you would usually use the teammemberships entity. However you will notice that this is not listed.
Fear not, scroll right to the bottom and select Enter custom value. Once done, type in teammemberships. You’ll also want to add a filter in to retrieve only the desired team. In this example I have used the guid of the team in the filter.
- Here comes the workaround: Because teammemberships wasn’t in the Entity list in the previous step, Flow doesn’t know how to handle the response. Put another way, it doesn’t know what fields the teammembership entity contains. Fortunately Flow uses the Web API so we can make use of the Parse JSON step to extract the info we need from the response.
- Once selected, select the List of Items from the Previous step
- Before moving on we must enter the schema that is used in the response from the Retrieve Dynamics Team Member step. Fortunately this can be entered by passing in an example response with Flow then working out the schema to use. Alternatively copy and paste the below:
{ "type": "object", "properties": { "@@odata.context": { "type": "string" }, "value": { "type": "array", "items": { "type": "object", "properties": { "@@odata.etag": { "type": "string" }, "ItemInternalId": { "type": "string" }, "systemuserid": { "type": "string" }, "versionnumber": { "type": "integer" }, "teammembershipid": { "type": "string" }, "teamid": { "type": "string" } }, "required": [ "@@odata.etag", "ItemInternalId", "systemuserid", "versionnumber", "teammembershipid", "teamid" ] } } } }
- Next add a Apply to each step, using the value of Parse JSON step to loop through
- For each team member returned we now need to retrieve that user’s email address from the user entity. For this we’ll use the Dynamics 365 – Get record (Preview) step
- Fortunately this time Users is selectable. For the Item identifier we’ll pass in the systemuserid from the Parse JSON step
- Still inside our Apply to each step add a Variables – Append to string variable action
- Select the name of the variable you created earlier and in the value
- Add the same step again but this time set the value as a semi-colon ;
- Come outside of the Apply to each step and add an Office 365 Outlook – Send an email action
- Click See more listed under Variables
- Finally, add the Team Member variable we created earlier to the To field and enter the content of the email.
- Create a schedule step
This was originally posted here.
*This post is locked for comments