Skip to content Skip to sidebar Skip to footer

Can't Disable (set To Read-only, Protect, Gray-out Etc.) A Field

I've run this code: Xrm.Page.data.entity.attributes.get('subject').setValue('Beep');; alert(Xrm.Page.ui.controls.get('subject').setDisabled); Xrm.Page.ui.controls.get('subject').se

Solution 1:

Your code is correct, so it should be working. The syntax used by @Daryl is correct to. Those two lines are equivalent. The shorter one is just syntactic sugar shortening the other. So, you should use his.

Xrm.Page.ui.controls.get("subject").setDisabled(true);
Xrm.Page.getControl("subject).setDisabled(true);

If you're alerting out and getting the contents of the method, it means that you're hitting the right component and the correct method. Yet, so say that despite the call, the control doesn't get disabled. I think you're wrong.

Here's what I think happens. The control gets disabled, then, before you have time to notice it, the form get updated, rendering away your disable operation.

Keep in mind that unlike the field data, the property of being disabled doesn't get stored to the database. If you design a field as protected, it'll stay that way. But if you set such a property from the JavaScript code on the client-side, the appearance is only going to last until a reload of the page is performed.

So, if you need to keep the fields disabled, either make them so from the GUI designer or fire an onLoad method doing it for you.

Solution 2:

I use the getControl function and it works fine. should be in the form:

Xrm.Page.getControl(controlId).setDisabled(disabled);

And remember, disabled controls will not be updated unless you set the submit mode to "always".

Post a Comment for "Can't Disable (set To Read-only, Protect, Gray-out Etc.) A Field"