Hide And Show Sections In Dynamics 365 Using Javascript

In Microsoft Dynamics 365,you can Hide and Show Sections using JavaScript,This is possible by using the “setVisible”property of formContext.

Log in to Dynamics and choose a “Solution” to learn how to hide and show sections in Dynamics 365.

To do the “Hide and Show Sections” activity in Dynamics, create an Entity.

The fields “First Section,” “Second Section,” “Third Section,” and “Hide and Show Sections” are among those in the entity create. The Hide and Show Field is a “option set” containing Names and Values.

After creating the fields, go to forms and add the fields along with some sections to the form.

Change the “Name of the Tab” and “Section” after adding the fields to the form for our convenience.

When you’ve finished filling out the form, save it and publish it. Next, go to “web Resource” and create a new “web Resource.”

Write the JavaScript code as it is displayed below in the text editor.

function HideSection(executionContext)
{
var formContext=executionContext.getFormContext();
var Value=formContext.getAttribute(“sun_hideandshowsections”).getValue();
//Here “sun_hideandshowsections” is a Schema Name of Field.
if(Value != null)
{
if(Value==1)
{
formContext.ui.tabs.get(“General4”).sections.get(“First Section 1”).setVisible(true);
// Here “General4” and “First Section 1” is Names of “Tab” and “Section”.
}
else if(Value==2)
{
formContext.ui.tabs.get(“General4”).sections.get(“First Section 1”).setVisible(false);
}
else if(Value==3)
{
formContext.ui.tabs.get(“General4”).sections.get(“Second Section 2”).setVisible(true);
}
else if(Value==4)
{
formContext.ui.tabs.get(“General4”).sections.get(“Second Section 2”).setVisible(false);
}
else if(Value==5)
{
formContext.ui.tabs.get(“General4”).sections.get(“Third Section 3”).setVisible(true);
}
else if(Value==6)
{
formContext.ui.tabs.get(“General4”).sections.get(“Third Section 3”).setVisible(false);
}
else
{
}
}
}

After finishing the JavaScript coding, go to the form’s properties and enter the values.

then save and publish the form, and you can view the results by opening the “Model Driven apps” and choosing the Entity, then running the test file.

Save and Publish the Entity in Model Driven apps.

The “Hide And Show Section” is a “Option Set” that has some options in accordance with “Hiding and Showing Sections” as seen in the above figure.

First Section in the figure on top is hidden.

The Second Section is likewise hidden in the image below and also Third Section.

By selecting the choices as displayed below, we can now display sections.

In this way, we are able to hide Sections based on how many Sections we actually need.

For any Help or Queries Contact us on info@crmonce.com or +918096556344.