​Show Hide Control on Form in JavaScript on Record Status Changed Dynamic 365

One of our client’s requirements was to show custom entity grid on opportunity form when the opportunity is closed as won. The client wanted the grid to be hidden otherwise.

To achieve the required, I added the custom entity grid to section on form and registered a custom JavaScript function with status reason field.

Learn more about our Microsoft Dynamics 365 services

JavaScript code of function function showHidSubGridProjectSectionOnStatusChange ()
{
var oppStatus = Xrm.Page. getAttribute(“statuscode”). getValue();
if (oppStatus == 3) {   //3 is for Won opportunity
Xrm.Page.ui.tabs.get(“Summary”). sections.get(“section_subgridProjects”). setVisible(true);
} else {
Xrm.Page.ui.tabs.get(“Summary”). sections.get(“section_subgridProjects”). setVisible(false);
}
}

To trigger the JavaScript function, click on “Close As Won” button and then click on OK button, the function will be called.

I am showing the highlighted section when opportunity status become won, otherwise I will hide it.

That’s it for today, I hope it helped you. If you have any question or queries, do not hesitate to reach out to us