Creating Pre-Defined Email Templates In Dynamics 365 Customer Service 


In customer service, we often encounter repetitive emails, such as acknowledgment emails for registered cases or service requests. To simplify this process, we can create standard email templates for such occasions.

Consider a scenario where you’re a product company handling warranty claims. After processing a claim, you need to notify the customer about the exchange of their product. While the core message remains the same, certain details like the customer’s name, sender’s name, tracking number, etc., vary for each email.

Rather than composing these emails from scratch every time, your service team can save time and improve efficiency by using pre-defined email templates. These templates allow for quick customization of dynamic values, ensuring consistent and prompt communication with customers.


In this blog, I’ll guide you through creating email templates and using them for your cases.

How to Create an Email Template:

Step 1: Navigate to the Customer Service Hub model-driven app in your Dynamics 365 CRM.

Step 2: Go to “Email templates” and click on “New email template”. Name your email template and specify its permission level—whether it’s for personal use only or can be used organization-wide.

 Step 3: Choose the template category, indicating the CRM entity on which you want to use this template. The template will only be available on records of that entity. Then, click “Create” to finalize and create the template.

Once you’ve created your email template, it’s ready for customization. Edit the template content according to your needs, and once you’re satisfied, simply save the template.


To insert dynamic values into your email template, locate the ribbon button labeled “</>Insert dynamic text.” Clicking on it will display a screen where you can select the desired dynamic values.

Depending on the category of the template and associated record types, you’ll see available options. For instance, if you’re working with the Case entity, you may have access to data from related entities such as Account, Contact, and User records.

For this example, let’s use the Contact’s first and last name, as well as the User’s name. These dynamic values will personalize the email content based on the recipient and sender information.

How to use this email template 

  1. Navigate to the entity for which you’ve created the template, in this case, it will be the Case entity. 
  2. Locate the timeline section on the Case entity form. If there’s no timeline, navigate to the Related section and find “Emails.” Click on it to proceed. 
  3. Once you’re in the email section, click on the “New” button to compose a new email. 
  1. In the email form, click on the “Insert Template” button, usually represented by an icon resembling a piece of paper or a template. 
  2. This will prompt you to select a field name. Choose “Regarding,” as this represents the record to which the email is related—in this case, the Case record. 
  3. Since the email template was created with the category “Case,” it will only be visible when you select “Regarding” as the field name. This ensures that the template pulls data from the Case record, such as the owner of the case or the contact associated with the case. 

Now hit select –> you will see a new pop-up and you will be able to find your template there.  

Hit save and you will have all the email content with dynamic values populated in the email body.  

Imagine simplifying all these steps into just one click. With a single button, emails are automatically generated from templates and sent to customers. Exciting, isn’t it?

Yes that is possible link to that blog is here check it out: Generated And Send Emails From Email Templates With a Button Click in Dynamics 365 Customer Engagement  

Hope this was a helpful read 😊!  Please leave your comments and suggestions in the comments below. 

Generated And Send Emails From Email Templates With a Button Click in Dynamics 365 Customer Engagement 

In the previous blog, I demonstrated how to create email templates in Dynamics Customer Service. This blog continues from there, showing you how to simplify the process of sending emails generated from these templates with just a button click.

If you’re new to this topic, I recommend referring to the first part of the blog for a better understanding. Creating Pre-Defined Email Templates In Dynamics 365 Customer Service  

Here, we’ll use JavaScript (JS) to call a Power Automate Flow. The JS function triggers upon a button click, passing the GUID of the case record clicked. 

(Note: Power Automate Flow can be triggered in various ways, not limited to button clicks. For instance, it can be initiated by changes in toggles.) 

Use case demo: 

As discussed previously, our email template contains fixed content and dynamic values like customer names and service team members’ names. 

In the previous method, users had to manually create emails, insert the template, and send them. 

In this blog, we’ll bypass these manual steps. Emails will be generated and sent with a single click. Users simply click the “send email” button on the case form. They’ll then see a progress indicator, and upon sending, receive a notification. 

Ribbon Button & JS 

Step 1: Add a ribbon button to the case form and insert the following JavaScript (JS) code into the ribbon button. Ensure to customize the notification messages and include your Flow’s HTTP request URL in the JS. 

var TriggerFlow = 
{
    Main: (executionContext) => 
    {
        debugger;
        var formContext = executionContext;
        //Strict Defined Parameters
        var RecordID = formContext.data.entity.getId().replace("{", "").replace("}", "");
        var EntityName = formContext.data.entity.getEntityName();
        formContext.data.save();
        //Find Plural Logical Name of the Entity and Call Flow
        Xrm.Utility.getEntityMetadata(EntityName, "").then(
            function (result) 
            {
                Xrm.Utility.showProgressIndicator("Please wait a moment...Shipping email record is being created")
                TriggerFlow.CallFlow({logicalEntityName: result.EntitySetName, CurrentRecord: RecordID});
            }, 
            function (error) 
            {
                console.log(error);
            }
        );
    },

    CallFlow: ({logicalEntityName, CurrentRecord}) =>
    {
        var flowUrl = "**********HTTP Request Link of your FLow***************";
        var inputdata = JSON.stringify({
                "RecordID": CurrentRecord
        });

        var req = new XMLHttpRequest();
        req.open("POST", flowUrl, true);
        req.setRequestHeader('Content-Type', 'application/json');
        req.send(inputdata);
        req.onreadystatechange = function () {

            if (this.readyState === 4) {
        
                req.onreadystatechange = null;
        
                if (this.status === 200) {                    

                    Xrm.Utility.closeProgressIndicator()
                    Xrm.Page.ui.setFormNotification("Email has been sent to the customer", "WARNING");                                       
        
                }
        
                else if (this.status === 400) {                    
                    
                    var result = this.response;
                    var alertStrings = { confirmButtonLabel: "Yes", text: "Error "+result, title: "Document was not generated" };
                    var alertOptions = { height: 120, width: 260 };

                    Xrm.Navigation.openAlertDialog(alertStrings, alertOptions).then(
                        function success(result) {
                            console.log("Alert dialog closed");
                        },
                        function (error) {
                            console.log(error.message);
                        }
                    );
                    Xrm.Utility.closeProgressIndicator()
        
                }
        
            }
        
        };  
    }
}

Step 2: Open the desired email template to be automated and copy its GUID. We’ll utilize this later in the process. 

Power Automate Flow Implementation. 

Step 1: Create a Power Automate flow with the trigger “When a HTTP request is received.” Include the following schema in your trigger configuration 

Step 2: Within the Power Automate flow, add a “Get a row” action for both the Case entity and the User entity. This action retrieves information about the specific case and user involved in the email generation process. For the User entity, ensure to input the GUID of the support user who will be set as the From-Party of the email. This GUID can be hardcoded in the action. 

Step 3: Add another “Get a row” action, this time for the Email Template entity. Use the GUID of the email template copied earlier to retrieve its details. 

Step 4: Next, incorporate an “Unbound action” titled “InstantiateTemplate.” Pass the necessary parameters as depicted in the image below. 

Step 5: Parse the Body from the unbound action with the below Schema. 

{
    "type": "object",
    "properties": {
        "@@odata.context": {
            "type": "string"
        },
        "value": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "@@odata.type": {
                        "type": "string"
                    },
                    "subject": {
                        "type": "string"
                    },
                    "description": {
                        "type": "string"
                    }
                },
                "required": [
                    "@@odata.type",
                    "subject",
                    "description"
                ]
            }
        }
    }
}

Step 6: Create an email record, the unbound action which we parsed will give us the Subject & Description (Email Body) that was generated from the template. 

 
Step 7: The final step is to perform a bound action on email message which we created and send success (200) response back to the JS. 

Response messages back to JS, you can setup your own error handing in this flow, if anything fails you can set a (400) response to the JS. 

Hope this was a helpful read 😊!  Please leave your comments and suggestions in the comments below.