Subject Field in email activity on Case

0
66
Forum Post: Change the Filter On option on Opportunity Associated View for Account form


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



Source link

Leave a reply

Please enter your comment!
Please enter your name here