​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);
}
}

form properties

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

close opportunity

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

Learn more about our Microsoft Dynamics 365 services

opportunity status

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! 

Leave a Reply

Your email address will not be published. Required fields are marked *