Hide And Show a Field in Dynamics 365 CRM Using JavaScript
Introduction:
In Dynamics 365, you can hide and show fields using JavaScript. This is useful if you have business logic that determines if fields are displayed or not to the user.
Implementation:
Let’s take an example where you would like to hide the Account field if the Contact field is populated.

Next, we can check if the Contact field is empty using getAttribute(“fieldname”).getValue(). If empty, we can hide the field using setVisible. Let’s add this to the change event of the Contact field:
function showAccountOnChange(executionContext)
{
formContext = executionContext.getFormContext();
if (formContext.getAttribute("parentcontactid").getValue() == null)
{
formContext.getControl("parentaccountid").setVisible(false);
}
else
{
formContext.getControl("parentaccountid").setVisible(true);
}
}
When Contact field is populated, the Account field is displayed:

When empty, the Account field is hidden and the field collapses (note this is v9 Dynamics 365):

Hope this helps …
Related posts:

How to Create Draft Time Entries from Hard Bookings in Dynamics 365 Project Operations
How an Australian Commercial Laundry Provider Automated Customer Emails and Contract Change Notifica...
How a U.S.-Based Consumer Appliance Manufacturer Automated FedEx Shipment Creation, Cancellation, an...

