GetListItems Returns "undefined" for a field

Nov 23, 2012 at 7:21 PM


I am trying to retrieve data from a list in sharepoint. With the fields 


And in the page I have written code to get data from this list. It is working but for 2 fields its returning undefined in the table i am creating with the data. All fields are showing not these two fields. 


I have cross checked the field names in the code many times, tried chenging the name also. But nothing is working. 

Below is my code 
var fieldsToRead =  "<ViewFields>" +
                               "<FieldRef Name='RISK_SLNO'/>" +
                                "<FieldRef Name='RISK_TYPE_HEADER'/>" +
                                "<FieldRef Name='RISK_TYPE'/>" +
                                "<FieldRef Name='RISK_HAVE_HEADER'/>" +
                                "<FieldRef Name='RISK_OWNER'/>" +
  "<FieldRef Name='RISK_RAGCURRENT'/>" +
    "<FieldRef Name='RISK_RAGPROJECTED'/>" +

var query = "<Query>" +
                             "<Where>" +
                                     "<Neq>" +
                 "<FieldRef Name='RISK_TYPE_HEADER'/><Value Type='Text'>~</Value>" +
                                             "</Neq>" +
                                                     "</Where>" +
                                                     "<OrderBy>" +
                                             "<FieldRef Name='ID'/>" +
                                     "</OrderBy>" +

operation: "GetListItems",
             async: false,
             listName: "riskmap_master",
             CAMLViewFields: fieldsToRead,
             CAMLQuery: query,
             completefunc: function (xData, Status) {             $(xData.responseXML).SPFilterNode("z:row").each(function() {

     var vRISK_ID = ($(this).attr("ows_RISK_SLNO"));
             var vRISK_TYPE_HEADER = ($(this).attr("ows_RISK_TYPE_HEADER"));
             var vRISK_TYPE = ($(this).attr("ows_RISK_TYPE"));
             var vRISK_HAVE_HEADER = ($(this).attr("ows_RISK_HAVE_HEADER"));
             var vRISK_OWNER = ($(this).attr("ows_RISK_OWNER"));
             var vRISK_RAGCURRENT =($(this).attr("ows_RISK_RAGCURRENT"));
             var vRISK_RAGPROJECTED=($(this).attr("ows_RISK_RAGPROJECTED"));
             var vRISK_COV = "LINKFORTEST";
             var vRISK_RED = "LINKFORTEST";

 //call a function to add the data from the row to a table on the screen                         AddRowToTable(vRISK_ID,vRISK_TYPE_HEADER,vRISK_TYPE,vRISK_HAVE_HEADER,vRISK_OWNER,vRISK_RAGCURRENT,vRISK_RAGPROJECTED,vRISK_COV,vRISK_RED);                                 }); } }); } 


Now the 2 lines 
             var vRISK_RAGCURRENT =($(this).attr("ows_RISK_RAGCURRENT"));
             var vRISK_RAGPROJECTED=($(this).attr("ows_RISK_RAGPROJECTED"));
returning undefined in the html table. Where as I tried to assign fixed value to the above like

             var vRISK_RAGCURRENT ="TEST_CURRENT";
And this worked, It showed in the table.

Kindly guide me, where I am doing wrong. 

This happened before also. I imported a excel spreadsheet to create a new list. And SPServices as not able to find the column names and returned undefined error. When I created the fields manually, it worked. Please tell me what I am missing here.

Nov 23, 2012 at 9:47 PM
For the rows that it is returning undefined, are those columns blank (empty/not set)?
In my experience, sharepoint GetListItems does not seem to return Fields (columns) if they are blank. Only when it contains data does it actually gets returned in the response.


Sent from mobile device.
Nov 23, 2012 at 9:54 PM

Thanks paul. But not any row is returning undefined. Its some columns. The mentioned columns in my post above are coming "undefined". And yes the cols do contain data.

Nov 23, 2012 at 10:39 PM

Are those two columns 'undefined' for all rows that you retrieve from the List 'riskmap_master'... Or only some rows have those two columns 'undefined' while others have other data on them?  I'm just trying to determine if those two field display OK for some rows and not others...

Could you paste the XML being returned by the GetListItems operation? Looking at the XML may help me help you :)


Run this from your page or from the browser developer tool (IE) or Firebug while on the page containing your code above:

  operation:    "GetList",
  listName:     "riskmap_master",
  completefunc: function(xData, Status) {
    $(xData.responseXML).find("Fields > Field").each(function() {
      var $node = $(this);
      console.log( "Type: " + $node.attr("Type") + " StaticName: " + $node.attr("StaticName") );

This will output the list definition along with all of the fields currently defined for your list along with their static name to the console (taken from the GetList documentation page.


Nov 24, 2012 at 4:58 PM

Odds are that you don't have the StaticName for the columns correct. Given the column names you show, I'd expect that the underscore character would be encoded in the StaticName.


Marked as answer by anuragsapanbharat on 12/12/2013 at 9:55 AM
Nov 25, 2012 at 11:48 AM

Thank you Paul & M, resolved the issue, it was due to static names. But what exactly is static name. It seems that when I am changing the column name the static name is not getting changed. How do i access static name of a perticular field by code. Any reference doc if you can help me with ?

Nov 25, 2012 at 2:26 PM

There's lots written about this on the Web. When you create a column, the StaticName and the DisplayName are created. When you change the DisplayName the StaticName stays, well, static.

See the entries in my Glossary.


Apr 19, 2013 at 10:04 AM
My code is as below, I want to call the below function from a different JS file and use the xdata further for looping in that file.

function GetSPListItemByQuery(ListName, Query, Viewfields) {
var URL = $().SPServices.SPGetCurrentSite() + "/TeamSite";
alert("URL" + URL);
    operation: 'GetListItems',
    webURL: URL,
    async: false,
    listName: ListName,
    CAMLQuery: Query,
    CAMLViewFields: Viewfields,
    completefunc: function (xData, Status) {
        alert("In GetSPListItemByQuery " + xData.responseXML);
        return xData;

However, xData is a valid odject in this context but returns "Null" to the calling function. Please advice.
Apr 19, 2013 at 10:14 AM
Please ignore the above post . It is resolved.

Thanks !