Featured Post

Web API Requests Series

Web API Series:  Create and Retrieve , Update and Delete , Retrieve Multiple , Associate/Disassociate , Impersonation , Run Workflows

25 March 2012

Read only fields are not saved.

If you are writing your custom web resource and using it to update standard crm fileds, rememember that they will not be saved if they are read-only.
Let me make myself clear with an example.
I was developing an HTML web resource and I was changing the value of a field only shown on the footer. In order to be able to change the value of that field I had to place it on the form as well and hide it. This means that I set, from the form designer, the following properties:
  1. Visible by default = false
  2. Field is read-only = true
If you do this you will be able to access the read-only field but when you save the form that field will not be saved because is read-only.
So what you should do is: Hide the field on the form but don't set the field to be read-only as shown below.















If it is a bug or it is normal, I don't know. If someone knows the reason of this behavior please let me know.
Thank you.

3 comments:

  1. I think it's done like this to reduce traffic from CRM to the database.

    I have written a blog post which will be published next week, which tells you how to send this field to be saved.

    You change change the submitMode value on a field and then it will publish the field.

    the link will work tomorrow
    http://crmbusiness.wordpress.com/2012/03/26/crm-2011-how-to-update-read-only-fields-with-javascript

    ReplyDelete
  2. Hey Luciano,
    You can use force submit in javascript

    Xrm.Page.get('field').setvalue("value");
    Xrm.Page.get('field').ForceSubmit = true;

    or similar code like this

    ReplyDelete