0

I'm using SPServices to query a SharePoint 2010 list, a can get the values that I want but when I try to sum all of then I get this"

enter image description here

Here is the code that i use:

var TotalAmount = 0.00;

$().SPServices({
operation: "GetListItems",
async: false,
listName: {list guid},
viewName: {view guid},
CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='AP' /><FieldRef Name='Amount' /></ViewFields>",
CAMLQuery: "<Query><Where><Eq><FieldRef Name='AP' /><Value Type='Text'>"+areaValue+"</Value></Eq></Where></Query>",
    completefunc: function (xData, Status){
        $(xData.responseXML).SPFilterNode("z:row").each(function(){
            var liHtml=$(this).attr("ows_Title");
            var app =$(this).attr("ows_AP");
            Amount = $(this).attr("ows_Amount");


            TotalAmount = TotalAmount + montante;


        });     
    }
      });
     alert(TotalAmount);

1 Answer 1

1

Not sure what is montante in your code was for ? where does it get its value from ? If you want to total of your amount column, below should work.

var TotalAmount = 0;

$().SPServices({
operation: "GetListItems",
async: false,
listName: {list guid},
viewName: {view guid},
CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='AP' /><FieldRef Name='Amount' /></ViewFields>",
CAMLQuery: "<Query><Where><Eq><FieldRef Name='AP' /><Value Type='Text'>"+areaValue+"</Value></Eq></Where></Query>",
    completefunc: function (xData, Status){
        $(xData.responseXML).SPFilterNode("z:row").each(function(){
            var liHtml=$(this).attr("ows_Title");
            var app =$(this).attr("ows_AP");
            Amount  =0;
            Amount = parseFloat($(this).attr("ows_Amount"));
            if(!isNaN(Amount))
            {
            TotalAmount += Amount;  
            }
        });     
    }
      });
     alert(TotalAmount);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.