[UPDATED] Microsoft Dynamics CRM 2011 – Using jScript with Disabled Fields
Here’s a little tidbit about Microsoft Dynamics CRM 2011 that took me a while to figure out, so I thought I’d share.
I recently wrote a jScript routine to calculate a tax amount on a Quote and place it in a field. Since the tax rate was not something that could be overridden, I set the field to Disabled.
Problem was, once I exported the field using “Print Quote for Customer,” the calculated tax field was coming out blank. This was mysterious – and maddening – because the value was being set right there on the screen, I could close and open the Quote and it looked just fine.
I learned that if the field is set to Disabled the value is not saved into the database, even if I modify it using jScript, unless you override using setSubmitMode (see below). (This is true whether in the UI or using the setDisabled() method.) In my case, I saw the value when I re-opened the Quote because there was an onLoad() event that was resetting it on the fly for me. In other words, when I closed the Quote, the field went to the database as null, and when I reopened it jScript filled in again, making it look like everything was working properly.
The lesson here is that even though jScript can change the value of a Disabled field in the user interface, the value won’t be saved.
My workaround was to re-enable the field and set the tax calculation to run when the field changed (onChange()), so even if a user modified the value, the system would immediately override it.
Update 2/2/2012
I recently learned that you can save changed but disabled fields. CRM doesn't save disabled fields as a performance issue, but you can override this behavior with:
Xrm.Page.getAttribute("fieldname").setSubmitMode("always");
I made a quick function in my library:
function setSubmitMode(fieldName)
{
Xrm.Page.getAttribute(fieldName).setSubmitMode("always");
}
Then in the onSave event, I called the function on the field. This forces CRM to save the value of the field.

Click here for more Microsoft Dynamics CRM tips and tricks.
Name (required)
Email (required)
Website