web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Luke Sartain Dynamics / Email Dynamics 365 team usi...

Email Dynamics 365 team using Microsoft Flow

Luke Sartain Profile Picture Luke Sartain 1,266

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:

    1. Create a schedule step01_Schedule
    2. Initialize a variable to store our team member email address in (more on why this is required later)07_Initialise_Variable
    3. Give this a suitable name and ensure it’s of type String08_Variable_Definition
    4. 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.  02_List_Records_Team_MissingFear 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.03_List_Records_Custom_Value
    5. 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.04_Parse_JSON_Step
    6. Once selected, select the List of Items from the Previous step05_List_of_Items
    7. 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"
                      ]
                  }
              }
          }
      }
      
    8. Next add a Apply to each step, using the value of Parse JSON step to loop through06_Apply_To_Each
    9. 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) step09_Get_Record
    10. Fortunately this time Users is selectable.  For the Item identifier we’ll pass in the systemuserid from the Parse JSON step10_Get_User
    11. Still inside our Apply to each step add a Variables – Append to string variable action11_Append_To_String
    12. Select the name of the variable you created earlier and in the value12_Add_Primary_Email
    13. Add the same step again but this time set the value as a semi-colon ;13_Semi_Colon
    14. Come outside of the Apply to each step and add an Office 365 Outlook – Send an email action14_Send_Email_Step
    15. Click See more listed under Variables 15_See_More
    16. Finally, add the Team Member variable we created earlier to the To field and enter the content of the email.

 

 

 


This was originally posted here.

Comments

*This post is locked for comments