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 :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Using JavaScript to lock a form or a section

(0) ShareShare
ReportReport
Posted on by 10
I have a form with a fair amount of JavaScript on it to ensure that only the proper fields are shown, which means that there are 60+ fields on this form and only 5 or 6 visible at a time. I'm saying this because making a business rule to lock all the fields based on a variable is not really feasible, especially since we'll be adding/removing fields as the needs for this form change.
 
So how can I use JavaScript to lock all the fields or lock the section they're in? I can't make the form Inactive or it won't show in the view, but the criteria is that if the parent form is turned on, I want this form locked so it can't be edited.
 
Thanks!
I have the same question (0)
  • Suggested answer
    Mohamed GRAIB Profile Picture
    2,508 Moderator on at
    Hi @MCerpa, 
     
    Yes it's possible to hide the section in your Form using JavaScript 
     
    can you try this ? 
     
    function hideSection(formContext, your tab name, your sectionName) {
       
        var tab = formContext.ui.tabs.get(tabName);  // Use this to get the tab name
        if (tab == null) {
            console.log("Tab: " + tabName + " not found");
            return;
        }
    
        var section = tab.sections.get(sectionName); // Use this to get the section 
        if (section == null) {
            console.log("Section: " + sectionName + " not found");
            return;
        }
    
        section.setVisible(false);  //=> Now this permit you to hide your section  
    }
    You must then add your web resources in the On load and on save events. 
     
    Please mark answer as verified if that's help. 
     
    Regards, 
     
    Mohamed GRAIB, 

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Manoj - ManoVerse Profile Picture

Manoj - ManoVerse 131 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 91

#3
Chris1968 Profile Picture

Chris1968 20

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans