Hi All,
I have a javascript on my field on-change. When ever field is modified javascript get fired and the field changes but when the form is saved the field is reverted back to old value.
Here is my javascript code.
function onChangecustom() {
debugger;
var quantity = Xrm.Page.getAttribute('quantity').getValue();
if (quantity != null) {
var customPercent = Xrm.Page.getAttribute("new_customs").getValue();
var shippingp = Xrm.Page.getAttribute('new_shippingpercent').getValue();
var margin = Xrm.Page.getAttribute('new_margin').getValue();
var CostPerUnit = Xrm.Page.getAttribute('new_costperunit').getValue();
var customcharges = 0;
var shippingcharges = 0;
var margincost = 0;
if (customPercent > 0) {
customcharges = (CostPerUnit * customPercent) / 100;
}
if (shippingp > 0) {
shippingcharges = (CostPerUnit * shippingp) / 100;
}
if (margin > 0) {
margincost = ((CostPerUnit + customcharges + shippingcharges) * margin) / 100;
}
var sellingprice = (CostPerUnit + customcharges + shippingcharges + margincost);
Xrm.Page.getAttribute('new_customcharges').setValue(customcharges);
Xrm.Page.ui.controls.get("new_customcharges").setDisabled(true);
Xrm.Page.getAttribute("new_customcharges").setSubmitMode("always");
Xrm.Page.getAttribute('new_shippingcharges').setValue(shippingcharges);
Xrm.Page.ui.controls.get("new_shippingcharges").setDisabled(true);
Xrm.Page.getAttribute("new_shippingcharges").setSubmitMode("always");
Xrm.Page.getAttribute('new_margin').setValue(margin);
Xrm.Page.getAttribute("new_margin").setSubmitMode("always");
Xrm.Page.getAttribute('new_margincharges').setValue(margincost);
Xrm.Page.ui.controls.get("new_margincharges").setDisabled(true);
Xrm.Page.getAttribute("new_margincharges").setSubmitMode("always");
Xrm.Page.getAttribute('new_totalcostperunit').setValue(sellingprice);
Xrm.Page.ui.controls.get("new_totalcostperunit").setDisabled(true);
Xrm.Page.getAttribute("new_totalcostperunit").setSubmitMode("always");
Xrm.Page.getAttribute('priceperunit').setValue(sellingprice);
Xrm.Page.ui.controls.get("priceperunit").setDisabled(true);
Xrm.Page.getAttribute("priceperunit").setSubmitMode("always");
var amount = Xrm.Page.getAttribute('priceperunit').getValue();
var total = amount * quantity;
Xrm.Page.getAttribute('baseamount').setValue(total);
Xrm.Page.ui.controls.get("baseamount").setDisabled(true);
Xrm.Page.getAttribute("baseamount").setSubmitMode("always");
Xrm.Page.getAttribute('extendedamount').setValue(total);
Xrm.Page.ui.controls.get("extendedamount").setDisabled(true);
Xrm.Page.getAttribute("extendedamount").setSubmitMode("always");
//Xrm.Page.data.entity.save();
}
//else {
// Xrm.Page.getAttribute('baseamount').setValue(sellingprice);
// Xrm.Page.ui.controls.get("baseamount").setDisabled(true);
// Xrm.Page.getAttribute("baseamount").setSubmitMode("always");
// Xrm.Page.getAttribute('extendedamount').setValue(sellingprice);
// Xrm.Page.ui.controls.get("extendedamount").setDisabled(true);
// Xrm.Page.getAttribute("extendedamount").setSubmitMode("always");
//}
}