Sorry I forgot to add that Line
function CountRecordsCCD() {
var recordId = Xrm.Page.data.entity.getId();
var fetchXmlQuery = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>"+
"<entity name='incident'>"+
"<attribute name='title' />"+
"<attribute name='createdon' />"+
"<attribute name='caseorigincode' />"+
"<attribute name='new_casenumber' />"+
"<attribute name='new_keycustomer' />"+
"<attribute name='incidentid' />"+
"<order attribute='createdon' descending='true' />"+
"<filter type='and'>"+
"<condition attribute='new_escalateassignto' operator='eq' uiname='CCD' uitype='team' value='" + recordId + "'/>"+
"<condition attribute='statecode' operator='eq' value='0' />"+
"<condition attribute='new_country' operator='eq' value='100000000' />"+
"</filter>"+
"</entity>"+
"</fetch>"
var req = new XMLHttpRequest();
req.open(
"GET",
Xrm.Page.context.getClientUrl() +
"/api/data/v9.0/incidents?fetchXml=" +
encodeURIComponent(fetchXmlQuery),
true
);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var results = JSON.parse(this.response);
var records = results.value[0].recordcount;
Xrm.Page.getAttribute("new_ccd1stweek").setValue(records);
} else {
alert(this.statusText);
}
}
};
req.send();
}