2

I am currently developing a news scroller/ticker in SharePoint Online (Office 365) and am using the follow script to access a list:

 var emptyResults = "<li>No current announcements</li>";

 $().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "newsList",
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
      completefunc: function (xData, Status) {
        var itemCount = $(xData.responseXML).find("[nodeName='rs:data']").attr("ItemCount");
                if (itemCount > 0) {
                    $(xData.responseXML).SPFilterNode("z:row").each(function () {
                        var titleHtml = "<li>" + $(this).attr("ows_Title") + "</li>";
                        $("#ticker").append(titleHtml);
                    });
                }
                else { $("#ticker").append(emptyResults); }
      }
});

Despite my list having an entry in it, the string 'No current announcements' gets written, suggesting itemCount is returning 0. Further debugging shows the Chrome Dev Console throwing the following error:

POST https://ontracsoftwaresolutions-8dca51b69a63f9.sharepoint.com/sites/dev/ntLive/_vti_bin/Lists.asmx 500 (Internal Server Error) 

Any thoughts?

  • Is the listName correct? – Robert Lindgren Sep 24 '13 at 11:19
  • /dev/Lists/newsList/ is the url for the list, so I would think so. – Ben Short Sep 24 '13 at 11:26
  • Leading from your extract from Chrome console, it seems your query gets executed agains /dev/ntLive, that is another web then you describes in the URL above :) – Robert Lindgren Sep 24 '13 at 11:27
  • 1
    Yes, slight oversight. Sorry about that. Trying to get my head around the 27,000 APIs and languages available and figure out which is going to be best for this solution. Thanks for your help. What is the best way to have a local SP app look for HostWeb? – Ben Short Sep 24 '13 at 11:38
  • 1
    I have managed to get it read both List.asmx files now but the /ntLive one still errors, not sure if that's stopping the other one from working properly. – Ben Short Sep 24 '13 at 12:45
2

Use the 'webURL' property of SPServices to define the target site, this will aim it at the correct directory for lists.

I then replaced

.find("[nodeName='rs:data']")

With

.SPFilterNode("rs:data")

Which now seems to work flawlessly.

| improve this answer | |
1

500 error happens when you try to get a list without spaces like you would with a /_vti_bin/ListData.svc call.

Example:

$scope.listCollection = [{
        "name": "Some List Title",
        "link": "SomeListTitle"
    }]

listCollection.name works

/_vti_bin/ListData.svc/Some%20List%20Title

listCollection.link does not

/_vti_bin/ListData.svc/SomeListTitle

With the ListData.svc, you can get the xml data list both ways. But when fetching with SPServices, you will receive the 500 error and need to call the actual title.

| improve this answer | |
0

This error /_vti_bin/Lists.asmx 500 (Internal Server Error) happen due to wrong List Name:

$().SPServices({
    operation: "GetListItems",
    async: false,
    webURL: "http://srv-abc",
    listName: "Workflow History",

I used Workflow list name but the actually the list name is Workflow History, that's why that error occurs.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.