Scenario Overview
This scenario is an improvement of Formula #83. The Business requirement here is to use an existing template email on CRM instead of generating the email within the Dialog.
The user will select the appropriate Sales Literature and select which email template they want to use. The N52 Formula manager will then create the email and attached the PDF documents.
Finally the Formula will send the email out to the customer automatically.
Email to Customer
North52 Decision Suite Solution
The North52 Decision Suite solution works like this:
- A formula of type 'Process Genie' set up on the Case entity
- A Dialog is created on the Case entity
- The dialog will display all available Sales Literature and ask the user to chose one to send to the customer
- The dialog will then ask the user which Template to use
- The dialog will then call the N52 formula via the Process Genie
- The formula will find the correct Template ID from the chosen template
- It will then create the email using the template
- Next it will retrieve the chosen Sales Literature Guid from the chosen Sales Literature
- Then it will attached all Sales Literature Items to the newly created email
- Finally it will send the email out to the customer
N52 Formula
Dialog Setup
Template Email
North52 Decision Suite Steps
The following set of steps outline how to create this Formula:
- Create the formula of type Process Genie on the Case entity called 'Case - Send Sales Docs'
- Create a FetchXML query called FindSalesLitItems on this formula and copy in the Fetch XML code from below
- Create an On-Demand Dialog on the Case entity as shown above
- Configure the Process Genie steps as shown in the below screenshot
- Click save and test
** Please see the below notes on the Formula Parameter XML
Process Genie
Formula Case - Send Sales Docs
SmartFlow(
SetVar('TemplateID', FindTemplateId([incident.template], '1033')),
SetVar('EmailID', CreateEmailFromTemplate(GetVar('TemplateID'),
[incident.incidentid],
'incident',
SetAttributePartyList('from','systemuser', WhoAmI()),
SetAttributePartyList('to','contact', [incident.customerid]),
SetAttributePartyList('cc', 'systemuser', WhoAmI()),
SetAttributeLookup('regardingobjectid','incident', [incident.incidentid]),
SetAttribute('subject',[incident.product] + ' - Product Information'),
SetAttribute('description',StringFormat([email.description], [incident.ticketnumber])))),
ForEachRecord(
FindRecordsFD('FindSalesLitItems',
true,
SetParams(GetParamFromUrl([incident.saleslit], 'id'))),
CreateNote(CurrentRecord('title'),
'email',
GetVar('EmailID'),
'North52',
CurrentRecord('filename'),
Currentrecord('mimetype'),
CurrentRecord('documentbody'))),
SendEmail(GetVar('EmailID'))
)SmartFlow(
SetVar('TemplateID', FindTemplateId([incident.template], '1033')),
SetVar('EmailID', CreateEmailFromTemplate(GetVar('TemplateID'),
[incident.incidentid],
'incident',
SetAttributePartyList('from','systemuser', WhoAmI()),
SetAttributePartyList('to','contact', [incident.customerid]),
SetAttributePartyList('cc', 'systemuser', WhoAmI()),
SetAttributeLookup('regardingobjectid','incident', [incident.incidentid]),
SetAttribute('subject',[incident.product] + ' - Product Information'),
SetAttribute('description',StringFormat([email.description], [incident.ticketnumber])))),
ForEachRecord(
FindRecordsFD('FindSalesLitItems',
true,
SetParams(GetParamFromUrl([incident.saleslit], 'id'))),
CreateNote(CurrentRecord('title'),
'email',
GetVar('EmailID'),
'North52',
CurrentRecord('filename'),
Currentrecord('mimetype'),
CurrentRecord('documentbody'))),
SendEmail(GetVar('EmailID'))
)
Fetch XML
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" >
<entity name="salesliteratureitem" >
<attribute name="filename" />
<attribute name="filetypecode" />
<attribute name="mimetype" />
<attribute name="documentbody" />
<attribute name="modifiedon" />
<attribute name="title" />
<attribute name="salesliteratureitemid" />
<order attribute="title" descending="false" />
<filter type="and" >
<condition attribute="salesliteratureid" operator="eq" uiname="Surface" uitype="salesliterature" value="{0}" />
</filter>
</entity>
</fetch>
Process Genie - Formula Parameter XML
<incident>
<template>{Email Template(Which Template email to send (Email Template))}</template>
<saleslit>{Record URL(Dynamic)(Which Sales Literature to send (Sales Literature))}</saleslit>
<productname>{Sales Literature(Which Sales Literature to send (Sales Literature))}</productname>
</incident>
Note 1: Formula Parameter Xml
The Formula Parameter Xml field allows us to pass additional data to the formula.
Syntax <entity><tag>information</tag></entity>
The entity has to match the entity type the Process Genie is working on, so if you are performing a context change in the Primary Entity ID field, then this entity should match it.
The tag is a name you give to the data so you can access it later
The formula can then access the data as if it is another attribute in the entity.
e.g. [incident.product]
Note 2 : Template Emails
You can pass additional information into the template by using the {0}, {1} parameters into template.
In this example, the subject line the Template is {0}.
When this line of code executes into the Formula:
SetAttribute('subject',[incident.product] + ' - Product Information'),
The {0} in the subject line will be replaced with the 'Bluetooth Pen - Product Information'
[email.subject] and [email.description]
If you want to replace multiple {0}, {1}, {2} values within the body or a subject bar of an email then you should use the StringFormat([email.description], 'value to be used') command.
Example: Hello {0}, How are you?
SetAttribute('description', StringFormat([email.description], 'John') = "Hello John, How are you?"
SetAttribute('description', 'John') = "John"
Without the [email.description] N52 will simply set the email description to John, the [email.description] command tells N52 that you want to merge your attributes with the existing data in the email body.
Assumptions
For this sample it is assumed there are Sales Literature PDF documents already set up on your instance of Dynamics 365.
Wizard - FindTemplateID
Please see below the wizard you can use to create the FindTemplateID() function call used in this formula.