Views:

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

Formula

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:
    SmartFlow( 
      SetVar('list', ''), 
      ForEachRecord( 
        FindRecordsFD('retrieveTeamMembers', true, 
          SetParams([email.regardingobjectid])), 
    
        SetVarConcat('list', StringFormat('systemuser^{0}|', CurrentRecord('systemuserid')))), 
    
    
      ForEachRecord( 
        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}" /> 
    </filter> 
    </link-entity> 
    </entity> 
    </fetch>

  • 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}" />         
    </filter>       
    </link-entity>     
    </link-entity>   
    </entity> 
    </fetch> 
    

Workflow

  • 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 Quick Buttons can be used on Dynamics Portals Entity Forms

That's right, you can trigger complex business rules via a button on an Entity Form. You could:

  • Retrieve information from another entity or even another system and return it to the form
  • Create or Update records on the button click
  • Process advanced decision logic from information that has been completed on the form but not submitted
  • Have dynamic buttons showing different options dependent on your business rules
  • And much more!

Learn more about North52 Quick Buttons for Dynamics Portals