Hi,
We are migrating our D365 for field service instance from old legacy web client to new the UCI. However, there is an issue which we are facing with the custom scripts on account form load. The script is working fine in legacy interface but in unified interface its not working. The code is basically for showing an information at the top bar about the customer agreements. Below is the code and screens snapshots.
The image above shows that the code is working fine and showing the notification bar at the top.
The image above shows that the JS is not working and notification bar is also not appearing.
Below is the JS code.
function accountFormOnLoad() {
debugger;
window.Xrm.Page.ui.clearFormNotification("1000");
var id = window.Xrm.Page.data.entity.getId();
if (id === "") return;
var agreementArray = [];
var options = "$select=msdyn_agreementId&$filter=msdyn_ServiceAccount/Id eq guid'" + id + "' and msdyn_SystemStatus/Value eq 690970001";
window.SDK.REST.retrieveMultipleRecords("msdyn_agreement",
options,
function (agreements) {
debugger;
for (var i = 0; i < agreements.length; i++) {
agreementArray.push(agreements[i]);
}
},
function(error) {
debugger;
alert("accountFormOnLoad " + error.message);
},
function () {
debugger;
if (agreementArray.length === 0) {
activeAgreementExists(id);
callNotification();
countWorkordersForAgreement(agreementArray[0].msdyn_agreementId, "1000");
} else {
countWorkordersForAgreement(agreementArray[0].msdyn_agreementId, "1000");
}
});
}
function countWorkordersForAgreement(id, messageNumber) {
debugger;
var workorderArray = [];
var daytimeCounter = 0;
var nighttimeCounter = 0;
var agreementName = "";
function handleWorkorderIncidentType(index) {
debugger;
if (index >= workorderArray.length) {
debugger;
var message = "Active agreement " + agreementName + ": Callouts used day = " + daytimeCounter + " and night = " + nighttimeCounter;
if (messageNumber !== undefined) {
window.Xrm.Page.ui.setFormNotification(
message,
"Info",
messageNumber);
}
return message;
}
window.SDK.REST.retrieveRecord(String(workorderArray[index].msdyn_PrimaryIncidentType.Id),
"msdyn_incidenttype",
"sirocco_CountType",
null,
function (incidentType) {
debugger;
if (incidentType.sirocco_CountType.Value === 1) {
daytimeCounter++;
}
if (incidentType.sirocco_CountType.Value === 2) {
nighttimeCounter++;
}
handleWorkorderIncidentType(index + 1);
},
function (error) {
debugger;
alert("retrieveAgreements: " + error.message);
}
);
return "";
}
window.SDK.REST.retrieveRecord(String(id),
"msdyn_agreement",
"msdyn_name,msdyn_SystemStatus",
null,
function(agreement) {
if (agreement.msdyn_SystemStatus.Value !== 690970001) return;
agreementName = agreement.msdyn_name;
var options = "$select=msdyn_workordertypeId&$filter=msdyn_name eq 'Original'";
window.SDK.REST.retrieveMultipleRecords("msdyn_workordertype",
options,
function (workorderTypes) {
debugger;
if (workorderTypes.length !== 1) return;
options =
"$select=msdyn_PrimaryIncidentType,msdyn_Agreement" +
"&$filter=msdyn_Agreement/Id eq guid'" +
id +
"' and msdyn_SystemStatus/Value eq 690970003" +
" and msdyn_WorkOrderType/Id eq guid'{" +
workorderTypes[0].msdyn_workordertypeId +
"}'";
window.SDK.REST.retrieveMultipleRecords("msdyn_workorder",
options,
function (workorders) {
debugger;
for (var i = 0; i < workorders.length; i++) {
workorderArray.push(workorders[i]);
}
},
function (error) {
debugger;
alert("retrieveAgreements: " + error.message);
},
function () {
debugger;
handleWorkorderIncidentType(0);
});
},
function (error) {
debugger;
alert("retrieveAgreements: " + error.message);
},
function () {
debugger;
});
},
function(error) {
debugger;
alert("retrieveAgreements: " + error.message);
});
}