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
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.
Mohamed Amine Mahmoudi
83
Super User 2025 Season 1
Community Member
54
Victor Onyebuchi
6