Writing column data with SPServices GetListItems

1.7k Views Asked by At

I'm trying to pull information from a list in SharePoint using SPServices (a jQuery library). I'm able to access the list just fine with the GetListItems operation but I'm having trouble pulling the values from the columns. Basically, in it's simplest form, I have a column called 'Title' and I want to print a list of all the values in that column. Below is my code, I'm not sure what I need to pull from 'x' and the documentation on codeplex isn't very thorough. I've checked quite a few other threads but none seemed to solve this issue. Any help would be wonderful.

    $().SPServices({
    operation:"GetListItems",
    async: false,
    listName: "Retention Test List",
    completefunc: function(xData, Status){
        //alert(xData.responseText);
        x = $(xData.responseXML).SPFilterNode("z:row")
        $(xData.responseXML).SPFilterNode("z:row").each(function(){
            document.write(x.innerHTML);


});
}
});
1

There are 1 best solutions below

0
On

Surprised you didn't get an answer. The key is to get the element you want using $(this).attr("ows_[My Column Name]"). You will need to find the real names e.g. ows_Title or ows_A_x0020_Space

In code fragments you can also use:

XmlConvert.EncodeName = converts all the special characters to equivalent _x00xx_
XmlConvert.DecodeName = converts all the _x00xx_ back to the special characters.

Quickly get the correct name to use in your code: Edit list settings, click on the column use the name as shown in the URL. Example : Field=A%5Fx0020%5FSpace . for "A Space"

    $(document).ready(function() {

    $().SPServices({
        operation: "GetListItems",
        listName: "Retention Test List",
        completefunc: function(xData, Status) {
            var seeMe = ""; 
            $(xData.responseXML).SPFilterNode("z:row").each(function () {
                seeMe += $(this).attr("ows_Title") + "<br/>";
            });
            $('.showme').html(seeMe); // or alert(seeMe); if so set "<br/>" to "<\n>"
        }
    });
});

HTH