Thank you Arun for helping me!
I made the changes but the messages are still displayed. Below are the messages:
Error in custom event for this field.
Field: window
Event: onload
Error: undefined
Error in custom event for this field.
Field: crmForm
Event: onsave
Error: undefined
Error in custom event for this field.
Field: name
Event: onchange
Error: undefined
As you advised me, I already selected the field "Pass execution context with a first parameter" and updated the code. With the change follows the new code:
// 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 attribute OnChange event
this.attributeOnChange = function (executionContext) {
var formContext = executionContext.getFormContext();
// Automatically set some field values if the account name contains "Contoso"
var Name = formContext.getAttribute("name").getValue();
if (Name.toLowerCase().search("contoso") != -1) {
formContext.getAttribute("description").setValue("www.contoso.com");
}
}
// Code to run in the form OnSave event
this.formOnSave = function () {
// Display an alert dialog
Xrm.Navigation.openAlertDialog({ text: "Record saved." });
}
}).call(Sdk);
Regards,