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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / JavaScript Form OnLoad...
Power Apps
Suggested Answer

JavaScript Form OnLoad event Error

(1) ShareShare
ReportReport
Posted on by 812
Hi All I have this JavaScript as a web resource in my solution set to the OnLoad event of a form.  Getting this error 
 
 
 
function makeRecordReadOnly(executionContext) {
    var formContext = executionContext.getFormContext();
    
   
    var botfreeze = formContext.getAttribute("xxxxx_botfreeze").getValue();
   
    if (xxxxx_botfreeze === true) {
        formContext.ui.controls.forEach(function (control) {
            try {
                control.setDisabled(true);
            } catch (e) {
                console.warn("Unable to disable control:", control.getName(), e);
            }
        });
    }
}
 

 
I have the same question (0)
  • Suggested answer
    Valantis Profile Picture
    4,810 on at
     
    The error is in your condition. You stored the value in a variable called `botfreeze` but then your if statement references `xxxxxx_botfreeze` directly which is the field logical name, not the variable.
    Change this:
    if (xxxxxx_botfreeze === true)
    To this:
    if (botfreeze === true)
    That is the only issue. The rest of the code seems correct.
     

     

    Best regards,

    Valantis

     

    ✅ If this helped solve your issue, please Accept as Solution so others can find it quickly.

    ❤️ If it didn’t fully solve it but was still useful, please click “Yes” on “Was this reply helpful?” or leave a Like :).

    🏷️ For follow-ups  @Valantis.

    📝 https://valantisond365.com/

     

  • Suggested answer
    11manish Profile Picture
    1,937 on at
    try below :
     
    function makeRecordReadOnly(executionContext) {
        var formContext = executionContext.getFormContext();
        
        var botfreeze = formContext.getAttribute("xxxxx_botfreeze").getValue();
       
        if (botfreeze === true) {
            formContext.ui.controls.forEach(function (control) {
                try {
                    control.setDisabled(true);
                } catch (e) {
                    console.warn("Unable to disable control:", control.getName(), e);
                }
            });
        }
    }
     
    • xxxxx_botfreeze is not a variable
    •  Your variable name is botfreeze
  • Valantis Profile Picture
    4,810 on at

    Hi @ctedesco3307,

    Just wanted to check in and see if everything is working now. If you still need any help, feel free to let me know.

    Also, if the issue is resolved, it would be great if you could mark the answer as solved so others with the same question can find it easily.

     

    Thanks and have a great day!

     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 762

#2
11manish Profile Picture

11manish 640

#3
Valantis Profile Picture

Valantis 548

Last 30 days Overall leaderboard