Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

JavaScript (Hiding sections)

Posted on by 220

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
    Kokulan 18,048 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans