Looking for PowerObjects? Don’t worry, you’re in the right place! We’ve been part of HCL for several years, and we’ve now taken the final step in our acquisition journey: moving our website to the HCL domain. Nothing else is changing – we are still fanatically focused on Microsoft Business Applications!

PowerObjects Blog 

for Microsoft Business Applications


Microsoft CRM Bit Field onChange() Event Not Firing As Expected

Post Author: Joe D365 |

I recently encountered some difficulty  firing a JavaScript event off when a bit field was marked as True. The following code worked fine when the bit field was a radio button on the form, but the event would not fire until I tabbed out of the field when I had the bit field formatted as a checkbox. This was in my onChange() event for the bit field.
hideField = function() {

if (crmForm.all.some_bit_field.DataValue == 1)
//Hide Some Fields
}

It came to my attention that checkbox-type bit fields are handled a bit differently in Dynamics CRM. The onChange () event for a checkbox will not be fired until we leave the field. This was a problem as the customer expected the field to show/hide immediately when the field was changed, not when we tabbed off the field.

To solve the problem we simply added some Event Handling code into the onLoad event area of our entity form. With this piece of code included, the field will show/hide as soon as the value changes, not when we tab off the field.

crmForm.all.your_checkboxfield.onclick = function() {
crmForm.all.your_checkboxfield.FireOnChange();
}

Using the code above, the onChange () event will fire TWICE: Once when the field is changed and once when we tab off the field. If this is a concern in your implementation you can use the following code in the onLoad() event to ensure the event only fires once (Remember to remove the code from the fields' onChange event is you use the code this way!)

crmForm.all.your_checkboxfield.onclick = function() {
    //Existing onChange() code
}

Happy Coding!

Joe CRM
By Joe D365
Joe D365 is a Microsoft Dynamics 365 superhero who runs on pure Dynamics adrenaline. As the face of PowerObjects, Joe D365’s mission is to reveal innovative ways to use Dynamics 365 and bring the application to more businesses and organizations around the world.

2 comments on “Microsoft CRM Bit Field onChange() Event Not Firing As Expected”

PowerObjects Recommends