0

I'm using GetListItems with query on SP page called for eg. "A" and everything is working there. Now I copied same code to second list B and in this list xData.responseXML is empty when I'm using CAMLQuery (order by query). But if I'm not using it, response I get is ok.

   completefunc: function (xData, Status) {
      console.log("is working here")
      $(xData.responseXML).SPFilterNode("z:row").each(function() { 
          console.log("but not working here")

Can you tell me why? Why some CAMLQuery is prventing to get me responseXML? And why its working on diffrent webpage? How it is possible?

EDIT: function added

I'm running it by

 getDefaultView()

and the function is:

    var getDefaultView = function(search_id){
    var list = "Projects";   //list name
    var method = "GetListItems";
    var fieldsToRead = "<ViewFields>" +
        "<FieldRef Name='ID' />" +
        "<FieldRef Name='ProjectCode' />" +
        "</ViewFields>";
    var query = "<OrderBy>" +
        "<FieldRef Name='ProjectCode'/>" +
        "</OrderBy>";
    if(search_id!=undefined){
        query = "<Query>" +
            "<Where>"+
            "<Eq>"+
            "<FieldRef Name = 'ID' /><Value Type='Text'>" + search_id +"</Value>"+
            "</Eq>"+
            "</Where>" +
            "</Query>";
    }
    $().SPServices({
        operation: method,
        async: false, 
        listName: list,
        CAMLQuery: query, //if commented everything works
        CAMLViewFields: fieldsToRead,

        completefunc: function (xData, Status) {
            console.log(xData); //here the response is displayed properly.
            console.log("is executing");
            $(xData.responseXML).SPFilterNode("z:row").each(function () {
                console.log("is not executing");
            });

        }
    });
};

And summarry:

  1. xData is full of data I asked. Both when using CAMLQuery query,and when not using query.

  2. Code below is executing only when CAMLQuery is commented

    $(xData.responseXML).SPFilterNode("z:row").each(function () { console.log("is not executing"); });

EDIT2:

POST message:

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<listName>Projects</listName>
<viewName></viewName>
<query>
<Query>
<OrderBy>
<FieldRef Name="ID"></FieldRef>
</OrderBy>
</Query>
</query>
<viewFields>
<ViewFields>
<FieldRef Name="ID"></FieldRef>
<FieldRef Name="ProjectCode"></FieldRef>
</ViewFields>
</viewFields>
<rowLimit>0</rowLimit>
<queryOptions>
<QueryOptions></QueryOptions>
</queryOptions>
</GetListItems>
</soap:Body>
</soap:Envelope>

And returned XML:

XML Parsing Error: reference to invalid character number Location: moz-nullprincipal:{c4f4a895-d0bb-45fc-b562-6de85f249fa5} Line Number 11642, Column 225:

...itle='Salesforce effectiveness operations toolkit&#11;' tag_ID='11407' tag_Un...
...-------------------------------------------------^
6
  • 2
    We need to see your CAML, and are you certain the field you are ordering by exists with the same internal name in this other list? Commented Feb 22, 2016 at 18:45
  • updated Eric. What do you think about it?
    – susanoo
    Commented Feb 23, 2016 at 7:54
  • anyone? Please help :/
    – susanoo
    Commented Feb 24, 2016 at 11:20
  • Again, are you sure the ProjectCode field exists in this other list and has the same internal name? Commented Feb 24, 2016 at 12:13
  • Eric - it was working with different list. Now I switched to "Projects", its working as it should but I'm not receiving "xData.responseXML". But the "xData" is full of data I requested. Added post msg in topic.
    – susanoo
    Commented Feb 24, 2016 at 13:08

1 Answer 1

2

I resolved this issue by function below:

   completefunc: function (xData, Status) {
            //alert(xData);
           // console.log(xData.responseText);
            var specialCharsDeleted = xData.responseText.replace(/&#11;/g, '');
            var xmlDoc = $.parseXML( specialCharsDeleted );
            $(xmlDoc).SPFilterNode("z:row").each(function () {
                console.log("its working");
}

so basicly SP was responsing with weird characers, I deleted them from text and converted again to xml.

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.