This simple JavaScript copies the title of the case and the case number into the subject line of a new email created for the case.
If you wish to modify the JavaScript and you are not sure how to do so, add your comment to this post and we will respond ASAP
Download Java Script from this location.
Settings>Customization>Customize the System
From the left pane select Web Resources and click New to create new Web Resource.
Name: EmailFromCase
Display Name: Email From Case
Type: Script (Jscript)
You can either use the Text Editor to copy and paste the JS or upload from file
Click Save
Now add the JS Web Resource to the Email Entity, and trigger the script on load (when you start new Email).
From left pane extend the Entities node. Scroll down to the Email entity>Forms and select Email main form.
Click: Form Properties
Click Add to add the “Email From Case” web resource to the Form Libraries section.
In the Event Handlers section click Add>Select EmailFromCase and enter the function name: EmailFromCase in the Function fields.
Click OK, Save & Publish All Customization
Testing the solution
GoTo Settings>Service>Cases and open a case
Click: Add Task and select Email
The subject line of the Email includes the Title of the case plus case number
by DNN Integration Dynamics
Hi,
I tried to add this JS in my Dynamics 365, but nothing happens? Does this only work for CRM 2013?
I was able to get this working with the below, I took out the get url function at the end and just hardcoded my crm url on the req.open line. Also added a missing ; on one of the lines too
//call this funciton onload of the email
function EmailFromCase() {
var CREATEDON=1;
var formType=Xrm.Page.ui.getFormType();
if(formType==CREATEDON){
RegardingOnchange();
}
}
//call this funciton onchange of regarding filed
function RegardingOnchange(){
roi = Xrm.Page.getAttribute("regardingobjectid").getValue()
if(roi != null){
var regarding=Xrm.Page.getAttribute("regardingobjectid").getValue()[0].entityType;
var id=Xrm.Page.getAttribute("regardingobjectid").getValue()[0].id;
var guid = id.replace(/{/g, "").replace(/}/g, "");
if( regarding!=null && guid!=null) {
if(regarding=="incident") {
var caseData=getCaseDetails(regarding,guid);
var subj=caseData[0]+" - "+caseData[1];
Xrm.Page.data.entity.attributes.get("subject").setValue(subj);
}
}
} else {
Xrm.Page.ui.setFormNotification("Could get object ID of regardingobjectid", "INFORMATION");
}
}
function getCaseDetails(entityName,recordId) {
Xrm.Page.ui.setFormNotification("Getting case details", "INFORMATION");
var reqXML="";
reqXML+="";
reqXML+="
";reqXML+="
";";reqXML+=" ";
reqXML+=" "+entityName+"";
reqXML+=" "+recordId+"";
reqXML+=" ";
reqXML+=" false";
reqXML+=" ";
reqXML+=" title";
reqXML+=" ticketnumber";
reqXML+=" ";
reqXML+=" ";
reqXML+=" ";
reqXML+="
reqXML+="";
var req = new XMLHttpRequest();
req.open("POST", "https://YOUR CRM URL HERE/XRMServices/2011/Organization.svc/web", false);
req.setRequestHeader("Accept", "application/xml, text/xml, */*");
req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Retrieve");
req.send(reqXML);
if (req.status == 200) {
var merge = req.responseXML;
if (merge != null) {
var mergeAttributes = null;
if (window.navigator.appName == "Microsoft Internet Explorer" || window.navigator.appName == "Netscape") {
if (navigator.appVersion.indexOf("Chrome") == -1)
mergeAttributes = merge.getElementsByTagName("a:KeyValuePairOfstringanyType");
else
mergeAttributes = merge.getElementsByTagName("KeyValuePairOfstringanyType");
}
else if (navigator.appVersion.indexOf("Chrome") != -1) {
mergeAttributes = merge.getElementsByTagName("KeyValuePairOfstringanyType");
}
for (i = 0; i < mergeAttributes.length; i++) {
var attr = mergeAttributes[i];
var key = attr.childNodes[0];
if (key != null && key.childNodes[0].nodeValue == "title") {
var caseTitle = attr.childNodes[1].childNodes[0].nodeValue;
}
if (key != null && key.childNodes[0].nodeValue == "ticketnumber") {
var ticketNum = attr.childNodes[1].childNodes[0].nodeValue;
}
}
return [caseTitle,ticketNum];
}
} else {
Xrm.Page.ui.setFormNotification("request status " + req.status , "INFORMATION");
}
}