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
-
Friday, March 19, 2010 11:12 AMModeratori would write a plugin that performs your calculations and this would allow you to determine when the total has changed by checking the InputParameters and then you could calculate the vat and update your vat amount.
MSCRM Bing'd - http://bingsoft.wordpress.com -
Friday, March 19, 2010 11:16 AM
Hi RhettClinton,
Thanks for ur prompt reply. Would you please show me some code example of Plugins if you have.
-
Friday, March 19, 2010 11:28 AMModerator
There are many examples out there, here is one for you http://www.devx.com/dotnet/Article/42660/1954. Personally for you solution I would be looking at a Pre Stage plugin that allows you to update the VatAmount in the Input Parameters which allows you to not have to call the update webservice. Similar to http://www.eggheadcafe.com/software/aspnet/33392665/how-to-modify-data-in-pre.aspx
The best thing to do is download the MSCRM SDK http://www.microsoft.com/downloads/details.aspx?FamilyID=82E632A7-FAF9-41E0-8EC1-A2662AAE9DFB&displaylang=en and this will give you a really good understanding plus references to all things CRM.
Let me know if you need anything futher.
Hope this helps,
Rhett
MSCRM Bing'd - http://bingsoft.wordpress.com- Marked As Answer by DavidJennawayMVP, Moderator Tuesday, May 11, 2010 3:16 PM
-
Friday, March 19, 2010 2:15 PM
Thanks Rhett,
Let me go thru this documentation and I'll let U know how it went.
Cheers
Jhelumi786