Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Suggested answer

Using JavaScript to lock a form or a section

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

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,353 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,251 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans