POWEROBJECTS

718 Washington Ave. N. Suite #101
Minneapolis, MN 55401
View map and all Locations

Send us a message

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() {

crm2011

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!

Avatar for JoeCRM

JoeCRM

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