I have an issue with the unified interface, in the classic interface when ever user try to create an email from case activities timeline. by default email to field used to populate with the account, in UCI this is changed and populating with contact value. So to fix this issue i wrote Jscript to get the account from related incident record and update it on Email to field. it's coming up with not found error.
function UpdateToField(executionContext) {
var formContext = executionContext.getFormContext();
var form = formContext.ui.getFormType()
var lookup= formContext.getAttribute("regardingobjectid").getValue(); // case lookup on email form
var newid = lookup[0].id.slice(1, -1);
var req = new XMLHttpRequest();
req.open("GET", formContext.context.getClientUrl() + "/api/data/v9.1/incident(" + newid + ")?$select=_new_organisation_value", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function () {
alert("stage1")
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response); // you will get the retrieved value in object we stored in result var.
var retrivedvalue= result._new_organisation_value; //get the id of the field
var retrivedformatedvalue= result["_new_organisation_value@OData.Community.Display.V1.FormattedValue"]; //get the formatted name of the field
if (retrivedvalue!= null) {
var value = new Array();
value[0] = new Object();
value[0].id = retrivedvalue;
value[0].name = retrivedformatedvalue;
value[0].entityType = "account";
alert("stage2")
formContext.getAttribute("to").setValue(value); //set the lookup value finally
}
else
alert("regarding value empty!!!!!!") // optional
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}
Any help would be greatly appreciated.