I am trying to set the total tax amount on the order form using jscript. I am able to put a value into the field but when i save/recalculate the tax amount does not stick. it gets over written with 0.00. I think this may be because there is no value in the Order Products tax field.
I have written a clunky script to help me see why I this is:
/// <reference path="XrmPageTemplate.js" />
function OWS_Library_calcTax() {
var ows_formType = Xrm.Page.ui.getFormType();
var ows_taxBase = 0.0875;
alert('OWS Form Type ' + ows_formType + 'Tax Base ' + ows_taxBase);
var ows_state = Xrm.Page.data.entity.attributes.get("shipto_stateorprovince").getValue();
var ows_orderTotal = Xrm.Page.getAttribute("totalamountlessfreight").getValue();
var ows_orderTax = ows_orderTotal * ows_taxBase;
if (ows_orderTotal > 0) {
alert('Tax total ' + ows_orderTax);
alert('Greater Than 0 so display OWS Order Total ' + ows_orderTotal);
alert('pre tax State is ' + ows_state);
}
switch (ows_state) {
case "california":
alert("california tax "+ows_orderTax);
Xrm.Page.getAttribute("totaltax").setValue(ows_orderTax);
break;
default:
alert("Not California of any kind");
}
}
I think I could get around this by applying the tax value in the order products section, but I am not sure how I can get the order shipto/billto state as each product also has an address attached to it. Anyone have any ideas?