CAMLquery getlistitems for renamed columns

Sep 6, 2010 at 1:53 PM

Hi, I am new to this, tried to search for an answer, but did not find it yet.

i use the next piece of code:

 

$().SPServices({
  operation: "GetListItems",
  async:false,
  listName: "testjquery",
  CAMLViewFields: "<ViewFields><FieldRef Name='Titel' /><FieldRef Name='AddInfo' /></ViewFields>",
  completefunc: ShowListItemData
  });


  function ShowListItemData (xData, Status) {
    $("#listdata").html("").append("<b>This is the output from the GetListItems operation:</b>");
    $(xData.responseXML).find("[nodeName=z:row]").each(function() {
      var liHtml = "<li>" + $(this).attr("ows_Title") + " - " + $(this).attr("ows_AddInfo") + "</li>";
      $("#listdata").append(liHtml);
      });
    $("#listdata").append("<hr/>");
		}

 

The result is:

  • testrow1 - undefined
  • testrow2 - undefined

after a lot of searching i found that the column name was changed after creation.

using GetList I found this info:

  • Displayname StaticName
  • Titel               Title
  • Add Info        AddInfo

 

Defining the camlviewfield I need the displayname.(Titel instead of Title)

retreiving data from the xml I need the Staticname preceeded by ows_

How do I solve this for renamed fields

I tried

<FieldRef Name='AddInfo'

<FieldRef Name='Add Info'

<FieldRef Name='Add_x0020_Info'

but no succes

when I leave the camlviewfield empty, I get all the columns and can use ows_addInfo to get the value

Is there a way to retrieve the column with space in the displayname?

 

 

Coordinator
Sep 6, 2010 at 2:06 PM
manrot: You have to use the StaticName for all fields in ViewFields. It looks like that should be 'Title' and 'AddInfo' in this case. One trick you can use is to simply alert the resulting XML to see if you have an error: alert(xData.responseXML.xml); Note that there seems to be a bug ('feature'?) with GetListItems where more fields are returned than you actually request, regardless your settings. M.
Sep 6, 2010 at 2:14 PM
sympmarc wrote:
.... Note that there seems to be a bug ('feature'?) with GetListItems where more fields are returned than you actually request, regardless your settings. M.

thnx for the very, very quick response.

 

the 'feature' was the confusing part for me, but your remarks helped me resolving the issue.

it works now!