Scenario Overview
In this business scenario the requirement is to determine all the 'Sales Team' members of an Opportunity (i.e. an Access Team, new security feature in CRM 2013) & send them an Individual Email when the Opportunity reaches the 'Close' stage.
In the screenshot below we can see that the Sales Team currently has 3 members on the Opportunity.
North52 Decision Suite Solution
The North52 Decision Suite solution works like this,
- We create a formula to execute whenever the Stage of an Opportunity changes
- If the Stage is set to 'Close' then will perform our processing
- First we will execute a Fetch-Xml query to retrieve all the Team Members for the current Opportunity
- Next we will loop over these Users one by one calling an Action
- The Action takes a User & the total number of recipients as parameters to generate & send the email
North52 Decision Suite Steps
Formula Steps
- Create a new formula of type 'Save - Perform Action'
- Set the Source entity to 'Opportunity'
- Set the Source Property field to 'Stage'
- Copy & paste the formula below into the formula description field & click save
Formula Detail Steps
- Scroll half way down the formula & click to add a new formula detail record (i.e. add the fetch-xml query)
- Set the Name to 'RetrieveTeamMembers'
- Copy & paste the fetchxml below into the query field & click save
Action Steps
- Create a new Action within MS CRM
- Set the name of the Action to 'Send Email Closing Opportunity'
- Set the Unique Name to 'SendEmailClosingOpportunity'
- Create an Argument called 'emailto', set the Type to EntityReference and make it required
- Create an Argument called 'numberofrecipients', set the Type to Integer and make it required
- Now add a 'Send Email' step to the Action
- Use the 'emailto' to set the 'To' field of the email
- Use the 'numberofrecipientsemailto' within the description field of the email
Formula
if( FindValue('processstage',
SetFindAnd('processid', 'processstageid'),
SetFindAnd([opportunity.processid], [opportunity.stageid]), 'stagename') = 'close',
ForEachRecord(
FindRecordsFetchXml( StringFormat(GetFetchXml('RetrieveTeamMembers'),
[opportunity.opportunityid])),
ExecuteAction('new_SendEMailClosingOpportunity',
'opportunity',
[opportunity.opportunityid],
SetAttributeActionLookup('emailto', 'EntityReference', 'systemuser',
CurrentRecord('systemuserid') ) ,
SetAttributeAction('numberofrecipients', 'Integer', RecordTotal() )
))
,'NoOp')
Fetch-XML
<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>