How to save (disabled) textbox value to crm 2011 database through javascript ?

Proposed Answer How to save (disabled) textbox value to crm 2011 database through javascript ?

  • Friday, August 24, 2012 7:04 AM
     
      Has Code

    Hello,

    I am saving crm form fields values using JavaScript and it showing that it saved.. but in database it is not saved.

    I am saving disabled fields value,i don't know this is problem or not.

    I am writing here my code for reference.

    function DropDownSelect()
    {
        var itemTaxGroup;
        var options = Xrm.Page.getAttribute('new_itemtaxgroup').getOptions();
    
        var selectedOption = Xrm.Page.getAttribute('new_itemtaxgroup').getSelectedOption().text;
    
        var s = selectedOption.match(/\d+/g);
        if (s.length > 1) 
        {
            itemTaxGroup = s[0] + "." + s[1];
        }
        else
            itemTaxGroup = s[0];
        //alert(itemTaxGroup);
        var detailAmount = Xrm.Page.getAttribute('totallineitemamount').getValue();
        //alert(detailAmount);
        var totalTax = ((detailAmount * itemTaxGroup) / 100);
        //alert(totalTax);
        Xrm.Page.getAttribute('totaltax').setValue(totalTax);
        var totalAmount = totalTax + detailAmount ;
        Xrm.Page.getAttribute('totalamount').setValue(totalAmount);
    }


All Replies

  • Friday, August 24, 2012 7:24 AM
     
     

    Hi Milan,

    This is a known issue. whichever fields is disabled by CRM or you've disabled it at some event. The field value will not be populated in the object which is being sent to CRM.

    The best workaround is to enable field by writing JavaScript on save event of the record. then CRM will save that field value.


    Thanks and regards,
    Hiren Solanki.
    Please vote or mark as a answer if it helped you.

  • Friday, August 24, 2012 7:40 AM
     
     
  • Friday, August 24, 2012 9:35 AM
     
     Proposed Answer Has Code

    Hi,

    I'm sure one of the links above will mention this as well, you can set the submit mode of each field to 'always'. This will allow the modified value to be saved for disabled fields. Add the line of code below for each disabled field you are setting:

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

    Best practice is to add this directly into the function just after you change each value. Just make sure you are not calling this function onLoad every time, otherwise it will always appear that changes have been made to the form, and the likes of print preview will no longer work. In this case you can add the code into the onSave event instead.

    Hope that helps!

    -Paul

    • Proposed As Answer by Oli Ward Friday, August 24, 2012 9:36 AM
    •  
  • Friday, August 24, 2012 10:13 AM
     
      Has Code

    I have done this ..

    But still its not saving..

    My code is as below..

    function DropDownSelect()
    {
        var itemTaxGroup;
        var options = Xrm.Page.getAttribute('new_itemtaxgroup').getOptions();
    
        var selectedOption = Xrm.Page.getAttribute('new_itemtaxgroup').getSelectedOption().text;
    
        var s = selectedOption.match(/\d+/g);
        if (s.length > 1) 
        {
            itemTaxGroup = s[0] + "." + s[1];
        }
        else
            itemTaxGroup = s[0];
        //alert(itemTaxGroup);
        var detailAmount = Xrm.Page.getAttribute('totallineitemamount').getValue();
        //alert(detailAmount);
        var totalTax = ((detailAmount * itemTaxGroup) / 100);
        //alert(totalTax);
        Xrm.Page.getAttribute('totaltax').setValue(totalTax);
        Xrm.Page.getAttribute('totaltax').setSubmitMode("always"); 
        var totalAmount = totalTax + detailAmount ;
        Xrm.Page.getAttribute('totalamount').setValue(totalAmount);
        Xrm.Page.getAttribute('totalamount').setSubmitMode("always"); 
    }
    
    function onSaveEvent()
    {
        Xrm.Page.getAttribute('totaltax').setSubmitMode("always"); 
        Xrm.Page.getAttribute('totalamount').setSubmitMode("always"); 
    }

  • Friday, August 24, 2012 10:24 AM
     
      Has Code

    Hi Milan,

    Can you try by replacing following in your save event ?

    Xrm.Page.getControl("totaltax").setDisabled(false);

    Xrm.Page.getControl("totalamount").setDisabled(false);



    Thanks and regards,
    Hiren Solanki.
    Please vote or mark as a answer if it helped you.

  • Friday, August 24, 2012 10:59 AM
     
     

    Hi Hiren,

    I tried it too. Does not make any difference.

    Its shown in form that its changing. But in in database it does not change.

  • Friday, August 24, 2012 11:46 PM
     
     

    The Detail AmountTotal Tax, and Total Amount on a Quote, Order, or Invoice is system calculated based on the Line Items.

    If you are trying to automate adding tax, you should apply this to each line item, instead of the whole invoice. 

    By adding the tax directly to each line item, the total tax will be rolled up to the invoice automatically, and your invoice report will add up correctly.

    You can also check this solution which adds a plugin to automate tax: http://www.magnetism.co.nz/solutionscasestudies/solutions/mtax.aspx

    Hope that helps!

    -Paul

  • Saturday, September 01, 2012 9:32 PM
     
     

    Did you manage to solve this?

    If so please mark the correct answer and vote helpful so the thread can be closed and other users can find the solution more quickly.

    Thanks

    -Paul

  • Wednesday, September 26, 2012 10:25 AM
     
     

    Hi Paul,

    I did not able to solve this problem.

  • Wednesday, September 26, 2012 10:47 AM
     
     

    Hi Milan,

    Paul is right in what he is saying, there is no way of modifying the total amount because it is calculated field. Have you tried adding the tax in the invoice product, instead of the invoice entity?

    In the invoice product, the prize is normally on the price list but you can add a discount or a tax, this is standard functionality. Then all the invoice products will come already with the tax and so the invoice.

    It is important to notice that what CRM does with the invoice product entity is quite funny. When you save the invoice product it is saved without any value on total amount, then it does an update and calculates the final amount.

    I did a plugin long time ago for this entity, the plugin had to populate some information from the invoice product entity to another entity and I had to run the plugin on Update because of this.

    Cheers,

    Mc