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!

To save the data on the form (like everyone else and like it's suppose to be) I clicked on Save. Next time I opened the form and those read-only fields were empty. Did the user edit, no. No, because the field was read-only.

Workaround

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.

Why didn't the data save?

Apparently blogs and other Microsoft CRM experts claim its to save network traffic. Really?
I tried to investigate, but not enough. I better leave it at this. It would be easier to ask the masters. Microsoft CRM product team, I would like to know:
  • Why didn't it save?
  • Was this by design?


Strange, but true. Strange because I don't know yet.