Hiding and Showing a Field in Dynamics 365 using JavaScript

Leave a comment

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.

Let’s say, on the Account form, you would like to hide the Fax field if the Ticker Symbol is populated.

First, get the field names by going into design mode:

Next, we can check if the ticker symbol 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 Ticker Symbol field:

function TickerChange() {
   if(Xrm.Page.getAttribute("tickersymbol").getValue() == null) {
       Xrm.Page.getControl("fax").setVisible(false);
   }
   else {
       Xrm.Page.getControl("fax").setVisible(true);
   }
}

Now when the ticker symbol is change from populated to empty, the fax field disappears.

Ticker Symbol populated, with fax field displayed:

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

 

ABOUT CARL DE SOUZA

Carl de Souza is a developer and architect focusing on Microsoft Dynamics 365, BI, Web, Cloud and Data Science.

carldesouza.comLinkedIn Twitter | YouTube

 

Leave a Reply

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