Thursday, March 21, 2013

How to save read-only fields in CRM 2011

What was I trying to do?

My CRM form had few calculated fields which were populated using Jscript. And since these were calculated, I didn't wanted users to intervene. So I made them read-only!

After customizing the form and script, I open the form as a user and tried to save the data on the form by clicking the Save button and I closed the form.

Next time I reopened the form and the read-only fields were empty (the opens used as calculated fields based on javascript).

Solution

On the OnSave event of the form, insert this snippet:
Xrm.Page.getAttribute("fieldName").setSubmitMode("always");

The fieldName is the read-only field that was updated using Jscript. If there are multiple 'Jscript updated read-only' fields on your form, you have to duplicate the above snippet for those fields as well.

Hope it helps!