Views:

Scenario Overview

In this scenario the business requirement was to automatically attach documents, from a SharePoint Site related to an Opportunityto an email and send that email to a customer.

For this example we are using Dynamics CRM with SharePoint Online. We are also assuming that all files in the SharePoint folder should be sent to the customer although we could filter them in the formula if we needed to.

SharePoint Folder

N52 Formula Manager Solution

The Formula Manager solution works like this,

  • Formula of type 'Process Genie' is created on the Opportunity entity
  • xCache records are created to store the SharePoint Username, Password and the SharePoint URL
  • workflow is set up on the Opportunity to create the email to the customer
  • North52 Process Genie step is added to the workflow
  • The Formula searches the SharePoint site for documents connected to the Opportunity   
  • Next it adds each document as an attachment to the email
  • Finally the formula sends the email

*Note: Although the Workflow executes on the Opportunity entity, the formula executes on the Email entity. This is achieved by 'Context-switching' within the North52 Process Genie. 
 

N52 Formula Manager Steps

The following set of steps outline how to create this Formula

  • Create the xCache records to store the SharePoint Username, Password and URL
  • Create a new Formula of type 'Process Genie'
  • Copy and paste the code below into the formula  
  • Create the Workflow and configure it as shown below
  • Click Save & Test!

xCache Records


Workflow



Email



Process Genie 

Note: Context-Switching is achieved here by passing the Record URL of the newly created email as the Primary Entity ID for the Process Genie to execute on.


Email to Customer
 
Formula

SmartFlow(
   
  ForEachRecord(

          SharePointFindDocumentsByFetchXml('opportunity',[email.regardingobjectid]),     
    
           CreateNote(currentrecord('fullname'), 
                      'email', 
                      [email.activityid] , 
                      'Notes', 
                      CurrentRecord('fullname'), 
                      CurrentRecord('filetype'),
             
                      SharePointGetFile(
                             xCacheGetGlobal('SharePoint_Demo_URL'),
                             xCacheGetGlobal('SharePoint_Demo_Username'),
                             xCacheGetGlobal('SharePoint_Demo_Password'),
                             true,
                            CurrentRecord('absoluteurl')
                           )
             )
                              
    ),
  SendEmail([email.activityid]) 
)

List of fields returned by SharePointFindDocumentsByFetchXml

documentid
sharepointcreatedon
relativelocation
modified
fullname
title
author
sharepointmodifiedby
sharepointdocumentid
filetype
readurl
editurl
ischeckedout
absoluteurl

Wizard - xCacheGetGlobal

Please see below the wizard you can use to create the xCacheGetGlobal() function call used in this formula. 

Note you will need to have created the key name beforehand