Skip to main content

Notifications

Announcements

No record found.

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!
  • Suggested answer
    Mohamed GRAIB Profile Picture
    Mohamed GRAIB 2,494 Super User 2024 Season 2 on at
    Using JavaScript to lock a form or a section
    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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,904 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,605 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans