hello all i am building a java script which will query email entity using regardingobjectId which will matched the incident(Case) guid and will retrieve the following email and update the subject line, yet so simple query i am getting an error where it shows there is no regardingobjectId in Microsoft.Dynamics.CRM.email , i know it must be one of those time where i have overlooked certain portion of the code and it punishing me,yet after spending many hours i came here to post this question , thanks for looking into this .
function toAccessMailContent(executionContext) {
var formContext = executionContext.getFormContext();
var caseID = formContext.getAttribute("ticketnumber").getValue();
var CaseGuid = Xrm.Page.data.entity.getId();
if (CaseGuid) {
CaseGuid = CaseGuid.replace("{", "").replace("}", "");
}
var emailActivityId;
Xrm.WebApi.online.retrieveMultipleRecords("email", "?$select=activityid&$filter=regardingobjectid eq " CaseGuid "").then(
function success(results) {
for (var i = 0; i < results.entities.length; i ) {
if (results.entities.length > 0) {
emailActivityId = results.entities[i]["activityid"].replace("{", "").replace("}", "");
}
else {
console.log("no value");
}
}
},
function (error) {
Xrm.Utility.alertDialog(error.message);
}
);
var entity = {};
entity.subject = "Case Record Created" " " caseID " " "Updated from Javascript";
entity.cts_source = "Created from OOB Workflow Updated from Java script";
Xrm.WebApi.online.updateRecord("email", emailActivityId, entity).then(
function success(result) {
var updatedEntityId = result.id;
console.log(updatedEntityId);
},
function (error) {
Xrm.Utility.alertDialog(error.message);
}
);
}