This is the code that is in the web resource for the HTML tag stripping. I don't think that this effects the email because the emails contained HTML tags long before I put this in place. Also, this is a separate field on the case form it is not placed in the actual description box. This is the only thing I have found that gets rid of the HTML tags for the description on the case form.
Would I need to put something in the actual CRM provided description box to get rid of these HTML tags? The email grabs what is in the description box and then uses that to generate the case assignment email?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Email Body</title>
</head>
<body>
<h3>Case Description</h3>
<div id="description"></div>
</body>
<script>
var RYR = window.RYR || {};
var Xrm = parent.Xrm;
RYR.retrieveEntityWebApi = function(entityName,recordId,additionalCriteria) {
var headers = new Headers({
"Accept": "application/json",
"Content-Type": "application/json; charset=utf-8",
"OData-MaxVersion": "4.0",
"OData-Version": "4.0"
});
fetch("/api/data/v8.0/"+entityName+"?$select=activityid,description&$filter=_regardingobjectid_value eq "+recordId,
{ method: 'GET',
headers: headers,
credentials: 'include' //without this header, the request will fail
})
.then(function(response){
return response.json();
})
.then(function(c){
if(c.value && c.value.length > 0) {
document.getElementById('description').innerHTML = c.value[0].description;
Xrm.Page.ui.tabs.get('general').sections.get('emailsection').setVisible(true);
}
})
.catch(function(err) {
console.log(err);
});
};
RYR.retrieveEntityOData = function(entityName,recordId,additionalCriteria,callback) {
var odataUrl = "/XRMServices/2011/OrganizationData.svc/"+entityName+"?$select=ActivityId,Description&$filter=RegardingObjectId/Id eq (guid'"+recordId+"')";
if(additionalCriteria) {
odataUrl += additionalCriteria;
}
var retrieveReq = new XMLHttpRequest();
retrieveReq.open("GET", odataUrl, false);
retrieveReq.setRequestHeader("Accept", "application/json");
retrieveReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
retrieveReq.onreadystatechange = function () {
if(callback) {
callback(this);
}
};
retrieveReq.send();
};
var processEmailResults = function (response) {
if (response.readyState == 4) {
var emails = JSON.parse(response.responseText).d.results;
if(emails.length > 0) {
document.getElementById('description').innerHTML = emails[0].Description;
Xrm.Page.ui.tabs.get('general').sections.get('emailsection').setVisible(true);
}
}
};
var retrieveEmailBody = function() {
var recordId = Xrm.Page.data.entity.getId().substr(1,36);//Get rid of '{' and '}'
if(!window.fetch ||
!Xrm.Page.context.getVersion ||
Xrm.Page.context.getVersion().split('.')[0] !== '8') {
RYR.retrieveEntityOData('EmailSet',recordId,'&$top=1&$orderby=CreatedOn',processEmailResults);
}
else {
RYR.retrieveEntityWebApi('emails',recordId,'&$top=1&$orderby=CreatedOn');
}
};
if(Xrm.Page.ui.getFormType() === 2) retrieveEmailBody();
window.RYR = RYR;
</script>
</html>