Row and item count

May 19, 2014 at 2:06 PM
I have been all over the discussions and feel I have followed the responses, but I am still missing something. I have several status. I would to return the count of each and write them to the page.

so for my Deleted status, I show an alert and increment. it will count 1,2,3,4 then start over at 1,2

currently I have 6 deleted. but I cannot get my count to return 6 or even write 6 to my page. I am able to return my data, I just cant get the count to work. Here is my code, any help would be appreciated.

thanks
[code]
var itemCount = 0;
    var itemdeleted = 0;
    var itemchanged = 0;
    var itemupdated = 0;
    var itemnochange = 0;
    var itemTotal = 0;
$().SPServices({
operation: method,
async: false,
listName: list ,
CAMLViewFields: fieldsToRead,
CAMLQuery: query,
completefunc: function (xData, Status) {
var $xData = $(xData.responseXML);
itemCount  = $xData.SPFilterNode("rs:data").attr("ItemCount");
alert(itemCount); // this value jumps
    $(xData.responseXML).find("z\\:row").each(function() {

        var title = $(this).attr("ows_Title");
        var parenttitle = $(this).attr("ows_ParentTitle");
        var newroute = $(this).attr("ows_NewRouteNumber");
        var proposed = $(this).attr("ows_ProposedChange");
        var linkUrl = $(this).attr("ows_Link");
        var single = $(this).attr("ows_Single");
        var size = single != "1" ? "2" : "";

        var title = title.replace(/&/g, '&');   

        if ( proposed  === "Deleted" ) {
        itemdeleted++;
                alert("itemdeleted = " + itemdeleted);
        }

        if(linkUrl != undefined)
        {
            var temp = linkUrl.split(',');

            liHtml += "<li><a href='" + temp[0]+ "' class='"+proposed.toLowerCase().replace(' ', '')+size+"' title='"+proposed+"' ";
            //alert(proposed);
            if(proposed === "Deleted")
            {
                liHtml += " onclick=\"return hs.htmlExpand(this, {objectType: 'ajax', width: '500', wrapperClassName: 'titlebar' } )\" ";
            }
            if ( proposed  === "Changed" ) {  
                itemchanged++;
                //alert("itemchanged = " + itemchanged);
            }
            if ( proposed  === "No Change" ) {  
                itemnochange++;
                //alert("itemnochange = " + itemnochange);
            }
            if ( proposed  === "Updated" ) {  
                itemupdated++;
                //alert("itemupdated = " + itemupdated);
            }   
            liHtml += ">";
            liHtml += newroute + "</a>";
            liHtml += "</li>";


        }
        else {
            if(itemCount != 1)
            {
                liHtml += "</ul>";
                liHtml += "<div class='clear spacer20'></div></div>";
            }

            liHtml += "<h3><a href='#"+title.replace(' ', '_').replace(' ', '_').replace(' ', '_')+"'>"+title+"</a></h3>";
            liHtml += "<div>";
            liHtml += "<!-- open accordion panel "+title+" -->";
            liHtml += "<ul>";

        }

        liHtml += RetrieveNodes(title); 



  });

  if( itemCount === itemTotal ) {

            //$('#itemdeleted').append(itemdeleted);
            //$('#itemchanged').append(itemchanged);
            //$('#itemnochange').append(itemnochange);
            //$('#itemupdated').append(itemupdated);

        }


} //close completefunc

}); //close spservices

return liHtml;
[/code]
Coordinator
May 20, 2014 at 1:11 PM
The issue is probably with this selector:
$(xData.responseXML).find("z\\:row")
It will only work in IE. Try using SPFilterNode instead.

If you aren't getting any output, then odds are you're never iterating through the items at all.

M.
May 21, 2014 at 11:55 AM
Thanks Mark,

I get an accurate output of my data, It just wont count. I was able to finally get a count, but I had to do in in a separate spservice function
[code]
function getCount(status) {

var query = "<Query><Where><Eq><FieldRef Name='ProposedChange' /><Value Type='Choice'>"+status+"</Value></Eq></Where></Query>";

$().SPServices({
operation: method,
async: false,
listName: list ,
CAMLViewFields: fieldsToRead,
CAMLQuery: query,
completefunc: function (xData, Status) {
var $xData = $(xData.responseXML);
itemCount = $xData.SPFilterNode("rs:data").attr("ItemCount");
var liHtml = "";

    if(status == "Deleted") {
    liHtml += "<li><a class='changetab' href=''>";
    liHtml += "Deleted " + itemCount + " routes";
    liHtml += "</a></li>";
    }
    if(status == "Changed") {
        liHtml += "<li>";
        liHtml += "Changed " + itemCount + " routes";
        liHtml += "</li>";

    }
    if(status == "No Change") {
        liHtml += "<li>";
        liHtml += "Leave " + itemCount + " routes unchanged";
        liHtml += "</li>";
    }
    if(status == "Updated") {
        liHtml += "<li>";
        liHtml += "Updated " + itemCount + " routes";
        liHtml += "</li>";
    }

    $('#items').append(liHtml); 

    } //close completefunc  

}); //close spservices 
}//close function

[/code]

I would really like to have it in the same function.
Coordinator
May 21, 2014 at 2:28 PM
Check the values you get back for proposed. If it's a lookup column, you'll get values like 1;#Updated, not just the text.

M.