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

Notifications

Announcements

No record found.

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,504 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 96 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans