locked
Read Only Field isn't saved after update via JScript RRS feed

  • Question

  • Hello community,

    I am trying to change values in a read-only / disabled field via JScript.

    Data is entered into another moneyfield and then weighted against a probability to give a weighted estimate.

    The weighted estimate is supposed to be read-only, or disabled, so users can't enter data.

    When I create the record, the data is saved. But then no update is possible anymore. The data changes whenever I change values in the estimate field or the probability field. It is set to dirty and the submit mode is dirty. But it isn't saved.

    Any ideas why this is so and how I can save updates to this field while making it read-only or disabled?

     

    Thank you very much!

    Jan Nebendahl

    Wednesday, October 19, 2011 9:27 AM

Answers

  • Hi Jan,

    A field that is marked as readonly will not be submitted to the database for update. To get the value of a readonly field saved to CRM, you need to use the following code

    CRM 4.0

    crmForm.all.<fieldname>.ForceSubmit();

    CRM 2011

    Xrm.Page.getAttribute(“CRMFieldSchemaName”).setSubmitMode("always");

    HTH

    Sam


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Proposed as answer by Sam - Inogic Wednesday, October 19, 2011 9:49 AM
    • Marked as answer by Jan Nebendahl Wednesday, October 19, 2011 9:57 AM
    Wednesday, October 19, 2011 9:48 AM
  • Hi Jan,

    The field needs to be set as 'dirty' so that CRM knows the field value has changed and should be submitted in the update of the record.  In a practical sense you need to add a line to the Javascript which changes the field value.

    In CRM 4.0 this was done by:

    crmForm.all.[fieldname].ForceSubmit = true;
    


    In CRM 2011 this is done by:

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

    This should force CRM to include the field when updating the record instead of ignoring the update.  Hope that helps.
     


    Kind Regards, Paul | http://crmconsultancy.wordpress.com
    • Marked as answer by Jan Nebendahl Wednesday, October 19, 2011 10:00 AM
    Wednesday, October 19, 2011 9:52 AM

All replies

  • Hi Jan,

    A field that is marked as readonly will not be submitted to the database for update. To get the value of a readonly field saved to CRM, you need to use the following code

    CRM 4.0

    crmForm.all.<fieldname>.ForceSubmit();

    CRM 2011

    Xrm.Page.getAttribute(“CRMFieldSchemaName”).setSubmitMode("always");

    HTH

    Sam


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Proposed as answer by Sam - Inogic Wednesday, October 19, 2011 9:49 AM
    • Marked as answer by Jan Nebendahl Wednesday, October 19, 2011 9:57 AM
    Wednesday, October 19, 2011 9:48 AM
  • Hi Jan,

    The field needs to be set as 'dirty' so that CRM knows the field value has changed and should be submitted in the update of the record.  In a practical sense you need to add a line to the Javascript which changes the field value.

    In CRM 4.0 this was done by:

    crmForm.all.[fieldname].ForceSubmit = true;
    


    In CRM 2011 this is done by:

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

    This should force CRM to include the field when updating the record instead of ignoring the update.  Hope that helps.
     


    Kind Regards, Paul | http://crmconsultancy.wordpress.com
    • Marked as answer by Jan Nebendahl Wednesday, October 19, 2011 10:00 AM
    Wednesday, October 19, 2011 9:52 AM
  • Hi Sam,

    thanks a lot, that was it. The different behaviour on create and update really got me.

    Jan

    Wednesday, October 19, 2011 10:00 AM
  • I hate to open up an old thread, but I found this while looking for something else.  I did a blog post with a little snippet of script that, if run in the onSave event, will force CRM to write all read only fields to the DB.  Hope this helps someone. 

    Here is the script
    Wednesday, December 14, 2011 5:58 PM
  • Hi all,

    I have a Required Read-only field, because it gets his value from an event.

    In my javascript I have: 

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

    But it still allows me save the entity without fill in the field.

    I'm reading about and seems all people say this is the correct line of code, but I don't understand why is not working for me.

    Any sugestions?

    Thanks!


    Js

    Thursday, July 19, 2012 2:23 PM
  • It wasn't working for me as well when I was trying to write this ( Xrm.Page.getAttribute("fieldName").setSubmitMode("always"); ) line onSave of entity form.

    However, when I wrote this on onLoad of entity form it worked!

    Thursday, August 2, 2012 10:27 AM
  • Thanks tabi,

    I resolve my issue like explain in this thread:

    http://social.msdn.microsoft.com/Forums/en-IE/crm/thread/1a108017-fa36-4ba8-83e2-aaf443525df5


    Js

    Thursday, August 2, 2012 1:32 PM