web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Subject Field in email activity on Case

(0) ShareShare
ReportReport
Posted on by

Can somebody please help with this issue at all.

When sending an email from a case i would like the subject and case id automatically populated in the email.

Can somebody point me in the direction of how to do this please. We are using dynamics online 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Saroj Das Profile Picture
    3,355 on at
    RE: Subject Field in email activity on Case

    Try like below while you are configuring send email.

    6177.case2.JPG

    6177.case2.JPG

    Thanks,
    Saroj

  • Community Member Profile Picture
    on at
    RE: Subject Field in email activity on Case

    Thanks for the reply. Would this only work when a email is processed by a queue. So a new email to case?

    I am looking for once a case has been created and you want to send a email that the subject is populated with the case id and Subject

  • Saroj Das Profile Picture
    3,355 on at
    RE: Subject Field in email activity on Case

    Are you sending email manually from CRM? Are the cases are created manually or Auto Case Create Rule is used?

    Thanks,

    Saroj

  • Community Member Profile Picture
    on at
    RE: Subject Field in email activity on Case

    Using Auto Case to create rules. This is working fine what i want to happen is when your in the case details under  activities and you select email the subject field is populated with the case id and subject for the user. All the users will be using web browsers to access this.

  • Saroj Das Profile Picture
    3,355 on at
    RE: Subject Field in email activity on Case

    Do you want the subject to be like this? and what do you mean by  users will be using web browsers to access this?

     

    emailSub.JPG

     

    Thanks,

    Saroj

  • Community Member Profile Picture
    on at
    RE: Subject Field in email activity on Case

    When i say web i mean users will only access the crm using web browsers not outlook CRM clients.

    What i want to happen is the same as whats in this link www.dynamicsobjects.com/.../Add-Title-and-Case-Number-to-the-Subject-Line-of-an-Email-sent-from-CASE-entity

    I have tried this but does not seem to work in the latest version of CRM online.

  • Suggested answer
    Saroj Das Profile Picture
    3,355 on at
    RE: Subject Field in email activity on Case

    try this working code.

    //call this funciton onchange of Regarding field

    function emailFromCase() {

       var CREATEDON = 1;

       var formType = Xrm.Page.ui.getFormType();

       if (formType == CREATEDON) {

           regardingOnchange();

       }

    }

    function regardingOnchange() {

       if (Xrm.Page.data.entity.attributes.get("regardingobjectid").getValue() != null) {

           var regarding = Xrm.Page.data.entity.attributes.get("regardingobjectid").getValue()[0].typename;

           var id = Xrm.Page.data.entity.attributes.get("regardingobjectid").getValue()[0].id;

           var guid = id.replace(/{/g, "").replace(/}/g, "");

           if (regarding != null && guid != null) {

               if (regarding == "incident") {

                   getCaseDetails(guid);                

               }

           }

       }

    }

    function getCaseDetails(recordId) {

      // alert(recordId);

       var serverUrl = Xrm.Page.context.getClientUrl();

       var result;    

       var oDataEndpointUrl = serverUrl + "/api/data/v8.1/incidents?$select=title,ticketnumber&$filter=incidentid eq " + recordId + "";

       //alert(oDataEndpointUrl);

       var service = new XMLHttpRequest();

       service.open("GET", oDataEndpointUrl, true);

       service.setRequestHeader("OData-MaxVersion", "4.0");

       service.setRequestHeader("OData-Version", "4.0");

       service.setRequestHeader("Accept", "application/json");

       service.setRequestHeader("Content-Type", "application/json;charset=utf-8");

       service.setRequestHeader("Prefer", "odata.include-annotations=\"OData.Community.Display.V1.FormattedValue\"");

       service.setRequestHeader("Prefer", "odata.maxpagesize=50");

       service.onreadystatechange = function () {

           if (service.readyState == 4) {

               service.onreadystatechange = null;

               if (service.status == 200) {                                                            

                   var requestResults = JSON.parse(this.response);                              

                   if (requestResults != null && requestResults.value.length > 0) {

                       for (var i = 0; i < requestResults.value.length; i++) {

                           var caseName = requestResults.value[i]["title"];

                           var caseNumber = requestResults.value[i]["ticketnumber"];

                           var subj = caseName + " - " + caseNumber;

                       }

                       //alert(subj);

                       Xrm.Page.getAttribute("subject").setValue(subj);                    

                   }

               }

           }

       }

       service.send();

    }

    Thanks,

    Saroj

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Subject Field in email activity on Case

    TRY THIS CODE ...IT REALLY WORKS. Call "emailFromCase" function on Email entity form load , Check "Pass execution context as first parameter" checkbox 

    function emailFromCase(executionContext)
    {
      var formContext = executionContext.getFormContext();
      var CREATEDON = 1;
      var formType =formContext.ui.getFormType();
      if (formType == CREATEDON)
        {
          regardingOnchange(executionContext);
        }
    }

    function regardingOnchange(executionContext)
    {
      var formContext = executionContext.getFormContext();
      if (formContext.data.entity.attributes.get("regardingobjectid").getValue() != null)
      {
        var regarding = formContext.data.entity.attributes.get("regardingobjectid").getValue()[0].entityType;
        var id = formContext.data.entity.attributes.get("regardingobjectid").getValue()[0].id;
        var guid = id.replace(/{/g, "").replace(/}/g, "");
        if (regarding != null && guid != null)
         {
           if (regarding == "incident")
           {
              getCaseDetails(executionContext,guid);
            }
         }
       }
    }

    function getCaseDetails(executionContext,recordId)
    {
    // alert(recordId);
    var formContext = executionContext.getFormContext();
    var serverUrl = formContext.context.getClientUrl();
    var result;
    var oDataEndpointUrl = serverUrl + "/api/data/v8.1/incidents?$select=title,ticketnumber&$filter=incidentid eq " + recordId + "";
    //alert(oDataEndpointUrl);
    var service = new XMLHttpRequest();
    service.open("GET", oDataEndpointUrl, true);
    service.setRequestHeader("OData-MaxVersion", "4.0");
    service.setRequestHeader("OData-Version", "4.0");
    service.setRequestHeader("Accept", "application/json");
    service.setRequestHeader("Content-Type", "application/json;charset=utf-8");
    service.setRequestHeader("Prefer", "odata.include-annotations=\"OData.Community.Display.V1.FormattedValue\"");
    service.setRequestHeader("Prefer", "odata.maxpagesize=50");
    service.onreadystatechange = function ()
      {
       if (service.readyState == 4)
        {
          service.onreadystatechange = null;
             if (service.status == 200)
            {
              var requestResults = JSON.parse(this.response);
              if (requestResults != null && requestResults.value.length > 0)
                {
                   for (var i = 0; i < requestResults.value.length; i++)
                    {
                     var caseName = requestResults.value[i]["title"];
                     var caseNumber = requestResults.value[i]["ticketnumber"];
                     var subj = caseName + " - " + caseNumber;
                    }
                 //alert(subj);
                formContext.getAttribute("subject").setValue(subj);
               }
            }
        }
      }
    service.send();
    }

  • KvRoploo Profile Picture
    10 on at
    RE: Subject Field in email activity on Case

    Nice! This solution helped me very much! Thank you Rakesh.

    Note: it is requered to tick the box "Pass execution context as first paramter" in the Handler Properties dialog.

  • Ainee ahsan Profile Picture
    40 on at
    RE: Subject Field in email activity on Case

    can anyone explain why we have created email fromcase and regardingonchange function and what exactly has been done in the code ?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans