How to Show/Hide Sections
Sections function as form controllers within Dynamics 365. With the use of JavaScript, you can implement logic to display or conceal these controls. Below is a snippet of sample code that can be easily ‘fixed’ to work for your use case.
To manipulate sections, you must identify the specific section’s unique name for the show/hide action. To locate section names: In the Form editor, identifying section names is straightforward. Simply choose the section elements within the modern Form editor and look for the “Name” field.
function sectionvisibility(executionContext) {
let formContext = executionContext.getFormContext();
if(formContext.getAttribute("FIELDNAME").getValue() == null) {
formContext.ui.tabs.get("TABNAME").sections.get("SECTIONNAME").setVisible(true);
}
else {
formContext.ui.tabs.get("TABNAME").sections.get("SECTIONNAME").setVisible(false);
}
}
If you would like to continue learning how to use JavaScript, we have an educational blog with many more examples of code.