Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Answered

Disable all fields under every section on a specific tab

Posted on by 20

I am converting old XRM code to work on UI and I can't seem to get the loops nested right.  Rather than just looping through controls and hard coding the section name "PERSONALINFORMATION" name, how can I just give the tab name "ContractTerms" then automatically loop through all sections and controls under that tab?

Here is what I have:

function OnLoad(executionContext)
{

let formContext = executionContext.getFormContext(); 


formContext.ui.tabs.get('ContractTerms')
.sections.get('PERSONALINFORMATION')
.controls.forEach((e) => e.setDisabled(true));
 

}

  • richardpanek Profile Picture
    richardpanek 20 on at
    RE: Disable all fields under every section on a specific tab

    Awesome, thanks for the help

  • a33ik Profile Picture
    a33ik 84,321 Most Valuable Professional on at
    RE: Disable all fields under every section on a specific tab

    Works for me.

  • richardpanek Profile Picture
    richardpanek 20 on at
    RE: Disable all fields under every section on a specific tab

    Still doesn't appear to work, does it for you?

  • Verified answer
    a33ik Profile Picture
    a33ik 84,321 Most Valuable Professional on at
    RE: Disable all fields under every section on a specific tab

    Ok. I mistyped. Should be controls, not control:

    function OnLoad(executionContext) {
    	let formContext = executionContext.getFormContext(); 
    	formContext.ui.tabs.get('ContractTerms')
    	.sections.forEach(function(section) {
    		section.controls.forEach(function(control) {
    			control.setDisabled && control.setDisabled(true);
    		});
    	});
    }

  • Suggested answer
    Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Moderator on at
    RE: Disable all fields under every section on a specific tab

    Hi richardpanek,

    Please debug your code.

    If I answer your question then please mark it as verified.

    Let me know if I can provide you with more details.

    Thanks
    Regards,

    Abdul Wahab
    Power Platform & Customer Engagement Developer/Lead/Solution Architecture/Project Manager
    Direct/WhatsApp:+923323281237
    E-mail: abdulwahabubit@outlook.com
    Skype: abdul.wahabubit
    Linkedin: www.linkedin.com/.../

  • richardpanek Profile Picture
    richardpanek 20 on at
    RE: Disable all fields under every section on a specific tab

    Unfortunately this doesn't seem to work, no error however it doesn't disable any of the fields like the original code posted does.

  • a33ik Profile Picture
    a33ik 84,321 Most Valuable Professional on at
    RE: Disable all fields under every section on a specific tab

    Hello,

    Check the following:

    function OnLoad(executionContext) {
    	let formContext = executionContext.getFormContext(); 
    	formContext.ui.tabs.get('ContractTerms')
    	.sections.forEach(function(section) {
    		section.control.forEach(function(control) {
    			control.setDisabled && control.setDisabled(true);
    		});
    	});
    }

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

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

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 228,588 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans