Wednesday, May 20, 2015

Send Email to Access Team Members

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.


N52 Formula Manager Solution

The Formula Manager 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

N52 Formula Manager 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 description 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 Description

 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 Description

 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>

No comments:

Post a Comment

How to Deploy your API as a web app or API app

  Before you can call your custom API from a logic app workflow, deploy your API as a web app or API app to Azure App Service. To make your ...