Saving Data When A CRM Field is Read-Only With JavaScript (setSubmitMode)

Saving data when a CRM field ist read-only is a often requriered use case, when data is fetched by javascript and written in such a field.

Many Developers don’t know in the first place, that if a CRM field is read-only on the client-side you have to set the submit mode of the attribute. Otherwise changes which are made through JavaScript code on the field (e.g. setValue) aren’t stored in the database.

The SubmitMode knows three different values (never, dirty and always), but to make sure that every change is correctly saved you should use the “always” keyword – like on the example shown below.

Xrm.Page.getAttribute("fieldName").setSubmitMode("always");

Learn more about the SubMode on the related MSDN article.