locked
Java script to sum fields RRS feed

  • Question

  • I am very new to Java.  Trying to sum several fields.  Working with the first two as a test.  these fields are currency, does that make a difference?

    I have carefully checked the field names and they are correct, however this script does not calculate.  I need another set of eyes!

    Here is the script that I have configured for OnLoad:

    function calculate()

    {

        var item1 = Xrm.Page.getAttribute("new_AdditionalRegis").getValue();
        if (item1 == null) {
            item1 = 0;
        }

        var item2 = Xrm.Page.getAttribute("new_Booth").getValue();
        if (item2 == null) {
            item2 = 0;
        }

        Xrm.Page.getAttribute["new_TotalExpenses"].setValue(item1 + item2);

    }

    Thank you for your help!  It is greatly appreciated!


    Joe La

    Wednesday, May 14, 2014 2:05 PM

All replies

  • Hi,
    the field names must be lower case (and the last row you used wrong brakets), try with:

    function calculate()
    {
    var item1 = Xrm.Page.getAttribute("new_additionalregis").getValue();
    if (item1 == null) {
        item1 = 0;
    }
    
    var item2 = Xrm.Page.getAttribute("new_booth").getValue();
    if (item2 == null) {
        item2 = 0;
    }
    
    var total = item1 + item2;    Xrm.Page.getAttribute("new_totalexpenses").setValue(total);
    
    }


    My blog: www.crmanswers.net - Rockstar 365 Profile

    Wednesday, May 14, 2014 2:26 PM
  • Thanks for the help, but it still does not calculate.  I am setting this up as "OnLoad" in the form.  Would it matter if I set it up as OnChange?

    This seemed like such a simple place to start with Java Scripts yesterday! :-)

    Best Regards


    Joe La

    Wednesday, May 14, 2014 4:21 PM