onSave Event on Order Form and Fields calculations

Answered onSave Event on Order Form and Fields calculations

  • Friday, March 19, 2010 10:58 AM
     
     

    Hi Everyone,

    I need to calculate the tax (VAT) for the total amount of order instead of individual order products. For that I have created a custom attribute (totalvat) and write the following formula on the onSave event of the order form.

    var TotalAmount = crmForm.all.totalamount.DataValue;

    var Rate = crmForm.all.new_vatrate.DataValue;

    if(TotalAmount != null && Rate != null)

    {

    var TotalVat = TotalAmount * Rate / 100;

    crmForm.all.new_totalvat.DataValue = TotalVat;

     

    My problem is that the totalvat is gets calculated before the TotalAmount updated and therefore its always wrong. e.g

    When I add 1st Order Product item (£100) and Press Recalculate button on the form, The TotalAmount shows £100 and TotalVat = 0.0.

    But if I press save or recalculate again, the totalvat gets refreshed by 17.5.

    Now if I add another Order Product Item (£100) and press save or Recalculate buttons on the Order Form, The TotalAmount shows £200 but totalvat still shows 17.5 unless I press save or recalculate buttons again.

     

    I believe that this is because when I press save button, my code gets executed but at that time the totalamount has not been refreshed by the system.

     

    Is there a way that I can hold my calculation until all the form fields gets refreshed or run my code after the TotalAmount has been updated?

     

    Any response would be appreciated.

     

    Regards

    Jhelumi786

     

All Replies