locked
Value is not getting save in disabled fields + CRM 2011 RRS feed

  • Question

  • hi,

    i have a lookup field(product) ,revenueamt field(currency datatype) and revenuetotal field(datatype)

    onload revenueamt field and revenuetotal field are disabled( which is readonly). onchnage event of the product field revenue field will be anabled and amount will be given

    this functionality in working fine, but the value are not getting saved when i save the form.

    i have tried using setSubmitMode in onchange and onsave event but still the value is not getting saved.

    please find the sample script

    function revenuetracking1()
    {
    if(Xrm.Page.getAttribute("new_revenueproduct1id").getValue() != null)
       {
             var lookup =Xrm.Page.getAttribute("new_revenueproduct1id").getValue()[0].id; 
           if(lookup != null)
             {
                        Xrm.Page.getControl("new_revenueamt1").setDisabled(false);
                        //Xrm.Page.getAttribute(“new_revenueamt1”).setSubmitMode(“always”);

             }  

        }
     else
        {
                Xrm.Page.getControl("new_revenueamt1").setDisabled(true);
                 Xrm.Page.getAttribute("new_revenueamt1").setValue(0);
         }

    }
    =====
    function amt1()
    {

    var amount1=Xrm.Page.getAttribute("new_revenueamt1").getValue() ;
    var amount2= Xrm.Page.getAttribute("new_revenueamt2").getValue();
    var amount3= Xrm.Page.getAttribute("new_revenueamt3").getValue();

    if(amount1 == null)
    {
          Xrm.Page.getAttribute("new_revenueamt1").setValue(0);
    }
    if(amount2 == null)
    {
          Xrm.Page.getAttribute("new_revenueamt2").setValue(0);
    }
    if(amount3 == null)
    {
          Xrm.Page.getAttribute("new_revenueamt3").setValue(0);
    }

    Xrm.Page.getAttribute("new_revenuetotal").setValue(parseFloat(amount1)+parseFloat(amount2) + parseFloat(amount3));
    //Xrm.Page.getAttribute(“new_revenuetotal”).setSubmitMode(“always”);
    }


    Thanks, Saraswathy Kumaravelu
    Friday, July 8, 2011 11:49 AM

Answers

  • Hi,

    Even I was facing similar issue, when we change the value of a disabled field via Jscript, those changed values were not getting saved !

    So, what I did was, the field's whose value I change via Jscript, set those field's setSubmitMode to always on the OnSave event of the entity.

    Xrm.Page.getAttribute(“fieldname”).setSubmitMode(“always”); // This should be put on the Onsave event. !

    This will work !!

     

    Hope this helps !!

     

    Thanks

    Srinath

    • Proposed as answer by srinathns Friday, August 19, 2011 1:43 PM
    • Marked as answer by Donna EdwardsMVP Saturday, August 27, 2011 5:29 PM
    Friday, August 19, 2011 1:42 PM

All replies

  •  You might want to give the following a try:

    if(amount1 == null)
    {
          Xrm.Page.getAttribute("new_revenueamt1").setValue(0);
          Xrm.Page.getAttribute("new_revenueamt1").setSubmitMode("always");
    }
    if(amount2 == null)
    {
          Xrm.Page.getAttribute("new_revenueamt2").setValue(0);
          Xrm.Page.getAttribute("new_revenueamt2").setSubmitMode("always");
    }
    if(amount3 == null)
    {
          Xrm.Page.getAttribute("new_revenueamt3").setValue(0);
          Xrm.Page.getAttribute("new_revenueamt3").setSubmitMode("always");
    }

    MSCRM 4 and CRM 2011 will determine that disabled or read-only values have changed when modified via client-side scriptins and so will not include the revised value in the message that CRM passes to the Platform layer to update the Database - hence values updated via Javascript will not be saved when the form refreshes without specifically setting them to be submitted.
    Was ForceSubmit in CRM 4, and believe is now setSubmitMode in 2011.
    Hope that helps.

    Kind Regards, Paul | http://crmconsultancy.wordpress.com
    Friday, July 8, 2011 12:01 PM
  • I have already worked on the suggestion you posted.,Which didnt actually happen to give the correct result, i'm aware that we have to use setsubmitmode to save the disable field values, but still not sure whythis is not working in this scenerio, still confused how to make it work :-( Thanks in advance


    Thanks, Saraswathy Kumaravelu
    Friday, July 8, 2011 12:31 PM
  • Once Check the isDirty property of both the fields in the OnSave event to confirm the chages are detected.

    • Proposed as answer by P McQ Tuesday, July 12, 2011 3:02 PM
    Friday, July 8, 2011 12:41 PM
  • The other thing that might be worth checking, presumably the revenuetracking1() function runs from the onChange event of the Product - but when does the amt1() function run?  Is this on the Form's onSave event - could be worth checking this function definately runs via an alert pop-up and checking that the value (parseFloat(amount1)+parseFloat(amount2) + parseFloat(amount3)) is okay for the new_revenuetotal field.

    Would be tempted to try the following:

    var revenueTotal = (parseFloat(amount1)+parseFloat(amount2) + parseFloat(amount3));

    alert("revenueTotal := " + revenueTotal );
    Xrm.Page.getAttribute("new_revenuetotal").setValue(revenueTotal);
    Xrm.Page.getAttribute(“new_revenuetotal”).setSubmitMode(“always”);
    alert("populated");

    To check that the alert popup definately appeara, and whether the field does get populated without error.


    Kind Regards, Paul | http://crmconsultancy.wordpress.com
    • Proposed as answer by P McQ Tuesday, July 12, 2011 3:02 PM
    Friday, July 8, 2011 2:23 PM
  • Hi,

    Even I was facing similar issue, when we change the value of a disabled field via Jscript, those changed values were not getting saved !

    So, what I did was, the field's whose value I change via Jscript, set those field's setSubmitMode to always on the OnSave event of the entity.

    Xrm.Page.getAttribute(“fieldname”).setSubmitMode(“always”); // This should be put on the Onsave event. !

    This will work !!

     

    Hope this helps !!

     

    Thanks

    Srinath

    • Proposed as answer by srinathns Friday, August 19, 2011 1:43 PM
    • Marked as answer by Donna EdwardsMVP Saturday, August 27, 2011 5:29 PM
    Friday, August 19, 2011 1:42 PM