web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

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

I have the same question (0)
  • Suggested answer
    Kokulan Profile Picture
    18,054 on at

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans