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.
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()) { control.setDisabled(true); } }); }
Hi Ramanathan,
ReplyDeleteI am not sure about why you are using the checks in the if statement. Can you clarify?
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!
ReplyDeleteHi i am using the same code, all the fields are getting locked . But the issue even after saving if i refresh the form all the fields become angain unlocked..
ReplyDeletePlease suggest me on this
I am not completely aware of the context of the issue, but it seems if you register the function on onload, it could fix the issue.
DeleteThank you! works like a charm!
ReplyDeleteI have 20 fields on form now if i want to disable 18 fields and remaining 2 fields enabled
ReplyDeleteHow should i processed
Any suggestions please
I would recommend to use a Json object to hold all the fields I want to enable. In the above code will add an additional if condition to exclude those fields.
DeleteI have 20 Fields on form. Now i have to disable 18 fields and remaining 2 fields should be enabled.
ReplyDeleteAny suggestions.