Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

JavaScript (Hiding sections)

(0) ShareShare
ReportReport
Posted on by 222

Hi Guys,

I need help please :)

I have done some JavaScript to hide sections based on field "option set" value.

Everything works fine, however when I save & close the record and reopen it, all sections become visible again.

Please see script below:

function ViewFormSection() {
debugger;
var riskType = Xrm.Page.getAttribute("new_risktype").getValue();
var sections = Xrm.Page.ui.tabs.get("RiskDetails").sections;
var visibilityByRiskType = {

"2": // Commercial Combined
{
"HKQ" : false,
"MCD" : false,
"CI" : false,
"BVW" : false,
},
"3": {//Computers
"HKQ" : false,
"MCD" : false,
"CI" : false,
"BVW" : false,
},
"4": { //Contract Works
"HKQ" : true,
"MCD" : true,
"CI" : true,
"BVW" : true,
},
// ALL
"1": {
"HKQ" : false,
"MCD" : true,
"CI" : true,
"BVW" : true,

}
};
for (var i in visibilityByRiskType[riskType]) {
if(typeof sections.get(i) == 'undefined' || sections.get(i) == null){
alert(i + ' section is undefined');
}
sections.get(i).setVisible(visibilityByRiskType[riskType][i]);
}
}

*This post is locked for comments

  • Suggested answer
    Kokulan Profile Picture
    18,054 on at
    RE: JavaScript (Hiding sections)

    Hi

    If your above script is only running on OptionSet field change, you would normally experience this issue.

    You have to call the same function on form load as well  if you are not already doing so.

    If you still have the issue, please update here, we should be able to help.

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 54

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans