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 BPA Solution

The North52 BPA 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's Data Packager helps move configuration data between instances

North52 Data Packager is an add-on for North52 Business Process Activities which enables you to easily move data from one instance to another.  Users simply select the records they would like to package up and North52 Data Packager adds the data to a data package sheet, ready for export. Moving the records to another instance requires the package solution to be imported and ‘unpacked’ on the target instance.

North52 Data Packager is ideal for:

  • Moving Dynamics configuration records
  • Copying Dynamics Portal records
  • Distributing demonstration data

Learn more about the North52 Data Packager