Hi,
We created a new entity for expense claims. Among others, there are following two important fields:
Kilometres: User enters number of kilometers in this field
Mileage: This is read-only field. The number entered in Kilometres field is multiplied by $0.30 and the result is shown in Mileage field. The calculation is done using a JScript.
The JScript is applied on form with OnLoad event and for field with OnChange event.
User enters the Kilimetres as 50. Mileage field shows the accurate result as $15 (i.e. 50 x $.30). User saved the form and closed.
Challenge: User re-opens the form and changes the kilometres from 50 to 75. Mileage field shows the correct value $22.50. However, when user clicks the Save button, the value in mileage is changed back to $15. The Mileage field does not save any new calculation except the one that was saved in it the first time.
Please advise where I am making mistake and what should be changed to solve the problem.
The JScript used for calculation is this:
function calculate()
{
var val1 = Xrm.Page.getAttribute("new_kilometres").getValue();
if(val1==null)return;
var result = val1 * .30;
Xrm.Page.getAttribute("new_mileage").setValue(result);
}
Thanks in advance,
Saima Munir