Scenario Overview

This article is an extension of xRM Formula #095. The requirement has been updated so that the Stakeholders of the Opportunity as well as the Sales Team must be emailed when an Opportunity is closed.

The Opportunity below has 2 stakeholders and 1 sales team member. Each will need to be a recipient on the email that is sent out.

North52 Decision Suite

The North52 Decision Suite solution works like this:

  • Formula of type Process Genie is created on the Email entity
  • Workflow is created that triggers on the Status change of an Opportunity
  • When the workflow is triggered it creates the Email
  • We then use a N52 Process Genie in the workflow to call the formula on the newly-created Email
  • This Formula uses a FetchXML query to retrieve the Sales Team members
    • These members are added to a string
  • The Formula then uses a FetchXML query to retrieve the Stakeholders 
    • These are then also added to the string
  • The list members are then added to the email's To list
  • Finally the Formula sends the email 

Note: The FetchXML query returns both the teammembership guid and the systemuserid guid. Therefore we must tell the SetAttributePartyList function which guid we want to use by setting the last parameter to 'systemuserid'.

Set up the Formula, FetchXML queries and Workflow


The following set of steps outline how to create this Formula:

  • Create a new formula, setting the following values in the Formula Guide:
    • Source Entity set to Email
    • Set Formula Type to Process Genie
    • Select the Classic editor
  • Change the Name of the formula to Email - Populate To with Contacts & Users
  • Click Save
  • Copy and paste the following into the formula editing canvas:
      SetVar('list', ''), 
        FindRecordsFD('retrieveTeamMembers', true, 
        SetVarConcat('list', StringFormat('systemuser^{0}|', CurrentRecord('systemuserid')))), 
        FindRecordsFD('retrieveStakeholders', true, SetParams([email.regardingobjectid])), 
        SetVarConcat('list', StringFormat('contact^{0}|', CurrentRecord('contactid'))) ),
      SetVar('list', TrimEnd(GetVar('list'), '|')), 
      UpdateRecord('email', [email.activityid], SetAttribute('to', '#', GetVar('list')) ) )

FetchXML queries

  • Create a FetchXML query called retrieveTeamMembers, using the following FetchXML:

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"> 
    <entity name="teammembership"> 
    <link-entity name="team" from="teamid" to="teamid" alias="ab"> 
    <filter type="and"> <condition attribute="regardingobjectid" operator="eq" value="{0}" /> 

  • Create a FetchXML query called retrieveStakeholders, using the following FetchXML:

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" >   
    <entity name="contact" >     
    <attribute name="fullname" />     
    <attribute name="contactid" />     
    <order attribute="fullname" descending="false" />     
    <link-entity name="connection" from="record2id" to="contactid" alias="ai" >       
    <link-entity name="opportunity" from="opportunityid" to="record1id" alias="aj" >         
    <filter type="and" >           
    <condition attribute="opportunityid" operator="eq" value="{0}" />         


  • Create a workflow and configure it as below:

  • Set up the Create Email step as follows:

  • Set up the Process Genie step and add in the Formula ShortCode and set the Primary Entity ID to the email as shown: 

  • Save and test! 

Email Sent to Team Members and Stakeholders

Did you know?

North52 Decision Suite helps streamline complex business processes

North52 Decision Suite is a cloud-based or on-premise decision management/decision engine platform for the Dynamics 365 and Power Platform that uses data, analytics and business rules to automate decisions.

Companies use North52 to streamline their processes, improve the quality of the decisions inside their Dynamics 365 systems, and shorten the time it takes to adjust to business and competitive changes.

Learn more about the North52 Decision Suite