Hello everyone,
I'm looking for some help with client side scripting using javascript. I've been stuck on this for a couple of days now looking through forums but I can't seem to find a solution.
I'm following this walkthrough from Microsoft - Tutorial: Write your first client script in model-driven apps - Power Apps | Microsoft Docs
I've followed each step word for word and copied the exact same code but I don't see any of the changes happen. Here's the code I'm using (exactly the same as what is in the walkthrough above):
// A namespace defined for the sample code
// As a best practice, you should always define
// a unique namespace for your libraries
var Sdk = window.Sdk || {};
(function () {
// Define some global variables
var myUniqueId = "_myUniqueId"; // Define an ID for the notification
var currentUserName = Xrm.Utility.getGlobalContext().userSettings.userName; // get current user name
var message = currentUserName + ": Your JavaScript code in action!";
// Code to run in the form OnLoad event
this.formOnLoad = function (executionContext) {
var formContext = executionContext.getFormContext();
// display the form level notification as an INFO
formContext.ui.setFormNotification(message, "INFO", myUniqueId);
// Wait for 5 seconds before clearing the notification
window.setTimeout(function () { formContext.ui.clearFormNotification(myUniqueId); }, 5000);
}
// Code to run in the column OnChange event
this.attributeOnChange = function (executionContext) {
var formContext = executionContext.getFormContext();
// Automatically set some column values if the account name contains "Contoso"
var accountName = formContext.getAttribute("name").getValue();
if (accountName.toLowerCase().search("contoso") != -1) {
formContext.getAttribute("websiteurl").setValue("https://www.contoso.com");
formContext.getAttribute("telephone1").setValue("425-555-0100");
formContext.getAttribute("description").setValue("Website URL, Phone and Description set using custom script.");
}
}
// Code to run in the form OnSave event
this.formOnSave = function () {
// Display an alert dialog
Xrm.Navigation.openAlertDialog({ text: "Record saved." });
}
}).call(Sdk);
I take this code and go the the Main Information Form in my Accounts table and add it as a JS Library and then setup the event handlers, again exactly as described and word for word. I'm using the unified interface, not sure if that makes a difference or not.
But, I don't see the notification at the top, the changes when the attribute changes or the pop-up when the record is saved. No errors when I open up dev tools in both Edge and Chrome either. Tried it in both regular and incognito modes.
Could someone please take a look and let me know what I might be doing wrong?
Thanks,
Neil.