Skip to main content



No record found.

Customer Service forum
Suggested answer

Setting Recipient and Regarding Field When Replying to an E-mail in Dynamics 365 CRM

Posted on by 24

I am working with Dynamics 365 CRM and need some assistance with handling e-mails in the interactive experience form. Specifically, I am trying to reply to an e-mail directly from the timeline.

Here’s what I have achieved so far:

I can modify the sender’s address to a default e-mail using JavaScript. Our own system sends the initial e-mail, so the sender is our own domain. When replying, the e-mail address defaults to this. I have a workflow that parses the e-mail and creates the contact and case according to customer values.

However, I am encountering two issues:

Recipient Address: I want to automatically set the recipient to the Case’s customer e-mail address when replying. Currently, I have to set this manually. Regarding Field: The ‘Regarding’ field is empty when replying, and I need it to be automatically set to the related case.

I'm not sure how to proceed as I'm not experienced.

Here's my default e-mail JS:

function setSender(executionContext, entityType, name, ID){
    var formContext = executionContext.getFormContext()
    // Set the "From" field
    var lookup = new Array();
    lookup[0] = new Object();
    lookup[0].id = ID; 
    lookup[0].name = name; 
    lookup[0].entityType = entityType;
    console.log("Default e-mail is set");
  • Suggested answer
    BK-17051419-0 Profile Picture
    BK-17051419-0 24 on at
    Setting Recipient and Regarding Field When Replying to an E-mail in Dynamics 365 CRM
    I was able to solve it with this script
    function onReplyButtonClick(executionContext) {
        var formContext = executionContext.getFormContext();
        var regardingObject = formContext.getAttribute("regardingobjectid").getValue();
        if (regardingObject && regardingObject[0].entityType === "incident") {
            var caseID = regardingObject[0].id;
            Xrm.WebApi.retrieveRecord("incident", caseID, "?$select=_customerid_value,incidentid").then(
                function(result) {
                    var customerID = result._customerid_value;
                    var customerEntityType = result['_customerid_value@Microsoft.Dynamics.CRM.lookuplogicalname'];                ;
                    var customerName = result['_customerid_value@OData.Community.Display.V1.FormattedValue'];
                    var toLookup = [];
                    toLookup[0] = {
                        id: customerID,
                        name: customerName,
                        entityType: customerEntityType
                    console.log("Recipient is set to case's customer email");
                    var regardingLookup = [];
                    regardingLookup[0] = {
                        id: caseID,
                        name: result._regardingobjectid_value_formatted,
                        entityType: "incident"
                    console.log("Regarding field is set to related case");
                function(error) {
        } else {
            console.log("The regarding field is not set to a case entity.");
  • Cui Hao Profile Picture
    Cui Hao on at
    Setting Recipient and Regarding Field When Replying to an E-mail in Dynamics 365 CRM

    I created a Case, set Customer as a user, and then sent him an email in the timeline, and found that the /Regarding/ field, as well as the email address, were already populated.

    Then after the user replied to the email, I replied to that user's email directly in the timeline again and found that the To and /Regarding/ fields were also already populated.
    So following the correct process, the /Regarding/ fields and the recipients are auto-populated.

    I'm not sure which steps you're having trouble with, if it's easier, could you provide a full screenshot for me to see?

    Best regards,
    Cui Hao

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .


André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,696 Super User

Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

nmaenpaa Profile Picture

nmaenpaa 101,148


Featured topics

Product updates

Dynamics 365 release plans
Liquid error: parsing "/forums/thread/details/?threadid=%27nvOpzp;%20AND%201=1%20OR%20(%3C%27%22%3EiKO))," - Too many )'s.