Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Custom JS working fine in legacy web client but not working in UCI

(0) ShareShare
ReportReport
Posted on by 347

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.

JS Working Fine -  Showing the Notification

The image above shows that the code is working fine and showing the notification bar at the top.

The JS is not working and no notification bar appearing in UCI.

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);
});
}

  • waleedbinafzal Profile Picture
    waleedbinafzal 347 on at
    RE: Custom JS working fine in legacy web client but not working in UCI

    Hi Henry,

    Thanks for the suggestions. The system I am currently managing is designed by someone else without proper documentation. So right now I am in the middle of nowhere. However, I am moving the scripts from Xrm. Page to contextual forms concept which is a tedious task. I am facing so many issues while doing this simple to look migration. For example, I am just writing a simple piece of code (see below for code reference) and getting an error. Can you help me with that?

    function accountFormOnLoad(executionContext) {

       debugger;

       var formContext = executionContext.getFormContext(); // get formContext

       formContext.ui.clearFormNotification("1000");

       var id = formContext.data.entity.getId();

    /*    if (id === "") return;

       var agreementArray = [];*/

       var level = "Info";

       var message = "Active agreement " + "00738" + ": Callouts used day = " + "4" + " and night = " + "2";

       /*if (id !== undefined) {*/

           formContext.ui.setFormNotification("Hello", "Warning", id);

       /*}*/

    }

    Error Message:

    Script-Issue.JPG

    Log File:

    UciError: Invalid value Warning for notificationLevel
    at i (wewillfixitsandbox.crm4.dynamics.com/.../app.js
    at p (wewillfixitsandbox.crm4.dynamics.com/.../app.js
    at S (wewillfixitsandbox.crm4.dynamics.com/.../app.js
    at wewillfixitsandbox.crm4.dynamics.com/.../8.js
    at wewillfixitsandbox.crm4.dynamics.com/.../app.js
    at wewillfixitsandbox.crm4.dynamics.com/.../app.js
    at l._executeInternal (wewillfixitsandbox.crm4.dynamics.com/.../app.js
    at l.execute (wewillfixitsandbox.crm4.dynamics.com/.../app.js
    at v.execute (wewillfixitsandbox.crm4.dynamics.com/.../app.js
    at ee.setFormNotification (wewillfixitsandbox.crm4.dynamics.com/.../8.js

  • Verified answer
    Henry J. Profile Picture
    Henry J. 5,237 on at
    RE: Custom JS working fine in legacy web client but not working in UCI

    Hello Waleed,

    A few things I can spot here

    #1 the setFormNotification Client API is the right one and should work.

    #2 Using Xrm.Page is deprecated and unsupported. You should replace it using this guidance:
    https://docs.microsoft.com/en-us/power-platform/important-changes-coming#some-client-apis-are-deprecated

    #3 Not sure if the issue comes from this, but why are you using the SDK.REST library and not making calls to the Web API directly using this?
    https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-webapi/retrievemultiplerecords

    Henry

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans