Javascript settings value not worked when form is saved

This question is not answered

Hi,

I newbie to Dynamics CRM 2011.
I'm trying to use a basic javscript ressource to set a value in a form field.

Here is my code :

 

var tmp = parseInt (crmForm.all.new_nbr_a.value) +  parseInt(crmForm.all.new_nbr_b.value);

crmForm.all.new_nbr_total.value= tmp;

 

The field is well set in my form but when i save my form, the value is not stored.

Do someone can give me a reason of this problem ?

Thanks a lot

 

All Replies
  • Hi,

    you are trying to write ms crm 4.0 code in ms crm 2011, for ms crm 2011 you need to write like below

    var tmp = parseInt(Xrm.Page.getAttribute("new_nbr_a").getValue()) +parseInt(Xrm.Page.getAttribute("new_nbr_b").getValue());  

    Xrm.Page.getAttribute("new_nbr_total").setValue(tmp);


    Need help in CRM Contact US | Our Blog | Follow US | Like our Facebook Page | Our Book

    Make sure to Vote as Helpful and  Mark As Answer ,if you get answer of your question.

  • Hi,

    it's better to use the new code, but the old one should work at all. Is your field marked as read-only to prevent the users from editing it manually? If that is the case you have to add something like this:

    Xrm.Page.getAttribute(“Field Name”).setSubmitMode(“always”);

    With that the field can be written from code even if it is read-only.

  • Thanks a lot.

    It's working