web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Client Side JavaScript...
Power Apps
Answered

Client Side JavaScript does not run at all

(1) ShareShare
ReportReport
Posted on by 16

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.

I have the same question (0)
  • Bipin D365 Profile Picture
    971 on at

    Hi @ndsza ,

     

    Add Alert in your code to check till what point code is executing.

     

    Also, add below statement in your code for both onload and attributes change method.

    debugger;

     

    Now open Dev tool and refresh your form to debug your code.

     

    Thanks,

    Bipin

     

    Kudos and accept my solution if helpful!

  • MayankP Profile Picture
    464 on at

    Hi @ndsza 

     

    just checking are you testing with account which has got "Contoso" in the account name field? script only works for accounts which got this text in account name..

     

    also look at following article regarding how to debug d365 javascript..

     

    https://cloudblogs.microsoft.com/dynamics365/no-audience/2015/11/29/debugging-custom-javascript-code-in-crm-using-browser-developer-tools/

     

  • Verified answer
    ndsza Profile Picture
    16 on at

    Hi everyone, thanks for the suggestions. I ended up reinstalling both Edge and Chrome and everything is working now. Not sure what the exact cause was, but this has fixed it for me.

     

  • srx_nstratton Profile Picture
    76 on at

    Yikes! Struggled with this for a few hours. Tried different browser on this machine and worked. That's a bit uncomfortable.

  • syedhaammadAli Profile Picture
    2 on at

    Hi I saw that this resolve alread but if this is occuring for ther use again dotn reinstall the browser try to refesh like CTRL+F5. for changing client always we need to do otherwise you can go ahead with the solution you 🙂

     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 711 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 319 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard