Hi All,
I have created a simple JavaScript function that shows/hides a field based on an optionset value. It works fine until it is being set as displayed for the first time, once it is displayed(visible), then unable to not display the field, even though I am setting the setVisible to false.
I have debugged the code, and all the values are passing fine, only the issue is the department is being displayed (while it is supposed to be hidden).
Here is the code:
function onload(executionContext) {
var formcontext = executionContext.getFormContext();
window.setTimeout(function () {
showhidefield(executionContext, formcontext);
}, 5000);
}
function showhidefield(executionContext, formcontext) {
debugger;
if (formcontext != null) {
}
else var formcontext = executionContext.getFormContext();
//var category = Xrm.Page.getAttribute("sf_category").getValue();
var category = formcontext.getAttribute("sf_category").getValue();
if (category!= "undefined" && category == 979730002) {
toggledisplay(formcontext, "sf_department", true);
}
else {
toggledisplay(formcontext, "sf_department", false);
}
}
function toggledisplay(formcontext, fieldname, bool) {
debugger;
var save = true;
if (bool) {
//Xrm.Page.getControl(fieldname).setVisible(bool);
//Xrm.Page.data.refresh(save);
formcontext.getAttribute("sf_department").setValue(null);
formcontext.getControl(fieldname).setVisible(bool);
formcontext.data.refresh(save);
}
}