locked
Jscript multiplication function giving error. RRS feed

  • Question

  • I am trying to do a simple multiplication function to calculate Mileage Cost when the user enters the Miles.  Getting error "You must enter a number between 0.00 and 1,000,000.00.  Here is the code:

    function MileageCalc_onchange()
    {
    var Mileage = Xrm.Page.getAttribute("synact_miles").getValue;
    var MileageCost = Xrm.Page.getAttribute("synact_mileagecost");
    var Rate = .565
    var Result = Mileage * Rate

    if(Mileage != null)
       {
          MileageCost.setValue(Result);
       }
    }


    Ken Compter

    Tuesday, October 15, 2013 12:14 PM

Answers

  • Hi,
    your code has several errors, the first getValue is missing the brackets, semicolon missing in 5th and 6th line. try with this code:

    function MileageCalc_onchange()
    {
    var Mileage = Xrm.Page.getAttribute("synact_miles").getValue();
    if(Mileage != null)
    {
    	var Rate = 0.565;
    	var Result = Mileage * Rate;
        Xrm.Page.getAttribute("synact_mileagecost").setValue(Result);
    }
    }


    My blog: www.crmanswers.net

    • Marked as answer by kcompter Tuesday, October 15, 2013 1:17 PM
    Tuesday, October 15, 2013 1:01 PM

All replies

  • Hi,

    Please check the data length of the "synact_mileagecost", and increase the size as your calculation is producing more value then the length of field.

    Thanks!

    Subhash

    Tuesday, October 15, 2013 12:52 PM
  • Hi,
    your code has several errors, the first getValue is missing the brackets, semicolon missing in 5th and 6th line. try with this code:

    function MileageCalc_onchange()
    {
    var Mileage = Xrm.Page.getAttribute("synact_miles").getValue();
    if(Mileage != null)
    {
    	var Rate = 0.565;
    	var Result = Mileage * Rate;
        Xrm.Page.getAttribute("synact_mileagecost").setValue(Result);
    }
    }


    My blog: www.crmanswers.net

    • Marked as answer by kcompter Tuesday, October 15, 2013 1:17 PM
    Tuesday, October 15, 2013 1:01 PM
  • That was it! Thanks. 

    Ken Compter

    Tuesday, October 15, 2013 1:17 PM