Friday, 3 February 2017

MSCRM - Disable all fields using javascript - Make fields read only

Hello all,

Below is a simple JavaScript  function that can disable all fields in a form by iterating through controls.

The below code is mobile(MoCA) compatible, so feel free to use it even on mobile based JavaScript development.

    function disableAllFields() {
        Xrm.Page.ui.controls.forEach(function (control, i) {
            if (control && control.getDisabled && !control.getDisabled()) {


  1. Hi Ramanathan,

    I am not sure about why you are using the checks in the if statement. Can you clarify?

  2. The condition is to disable only the enabled fields. Apart from that, with Initial version d365 mobile, there were few controls with missing functions like getDisabled. To tackle the same I had to check for the existence of function object before calling the same, let me know if you need more info. Appreciate your response!


Contact Form


Email *

Message *