top of page
  • William Wenzel

Dynamics CRM Tech Tip – Conditionally Show and Hide Fields on an Entity Form

Dynamics CRM Tech Tip – Conditionally Show and Hide Fields on an Entity Form – Part 2: Using Custom JavaScript

Part 2 of a 3 part series: Using Custom Javascript

In last week’s tech tip, we described how to show and hide fields in CRM using business rules. We also outlined some of the key limitations of using business rules which can make it difficult or impossible to implement complex logic.

Given these limitations, you may be required to write custom JavaScript code to account for your complex logic. By implementing your showing and hiding logic in JavaScript, you have much more flexibility in the type of logic you can implement.

The Xrm.Page object model makes it easy to toggle the visibility of fields using JavaScript. The general process for showing or hiding a field based on an attribute’s value is to:

1. Get the attribute which determines whether or not to show the field.

2. Loop over the controls for the field that will be shown or hidden and set their visibility.

For example, in our example from the previous tech tip we want to hide the “Submitted” field based on the “Required” field’s value. The following code will accomplish this:

// Get the value of the "Required" field. This value will determine

// if we should show the other approval fields.

var showFields = Xrm.Page.getAttribute("elogic_discount_approval_required").getValue();

// Get all of the controls associated with the "Submitted" field.

var submittedControls = Xrm.Page.getAttribute("elogic_discount_approval_submitted").controls;

// Loop over all of the controls for the "Submitted" field.

submittedControls.forEach(function (control) {

// Toggle control visibiltiy based on what the "Required" field is

// set to.



This example shows how to pull the value of the “Required” field and then set the visibility of other fields (in this example, the “Submitted” field) based on that value. Please note that this example only demonstrates how to set the visibility of the "Submitted" field, not all four fields demonstrated in the business rule tech tip.

Check back next week for the final tech tip in this series, which will summarize the two methods of implementing showing and hiding logic and outline when to use each.

bottom of page