Do I require permissions to run SPServices on Sharepoint?

302 Views Asked by At

I require assistance with Sharepoint. I've tried multiple ways to retrieve data from a list and have had little to no success, after much reading and searching I'm still no further ahead.

I am using a list made by another user, which I can add,edit and delete items from. When calling this list using SPServices I seem to hitting a wall. Here is my third attempt at trying to access the list and now I have received a 404 response and responsetext is null.

The URL is correct, cause it actually loads the list of values.

If i have an empty webURL parameter, the parameter of responsetext has a helpful SOAP response stating the following:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.</faultstring><detail><errorstring xmlns="http://schemas.microsoft.com/sharepoint/soap/">
    List does not exist.
    The page you selected contains a list that does not exist.  It may have been deleted by another user.
    </errorstring><errorcode xmlns="http://schemas.microsoft.com/sharepoint/soap/">0x82000006</errorcode></detail></soap:Fault></soap:Body></soap:Envelope>

Here is my call which when I define the webURL to point to the list, it always returns a http 404 with responseText=null no matter what the url is. This is not very helpful. The Url I am pointing to loads the list.

function getListItems_RFC(){
   var url = $().SPServices.SPGetCurrentSite() + 
                "/_vti_bin/listdata.svc/RFCExtract";
   console.log("getListItems_RFC() "+ url);
   $().SPServices({
            operation: "GetListItems",
            webURL: url,
            async: false,
            listName: "RFC Extract",
            CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
            completefunc: 
               function (xData, Status) {
                  console.log(Status); //outputs error
                  console.log(xData); //outputs array responseText:null and status:404
                       $(xData.responseXML).SPFilterNode("m:properties").each(function() {
                      var liHtml = "<li>" + $(this).attr("d:Title") + "</li>";
                      $("#debug").append(liHtml);
                  });
               } 
       });
};

I have modified the url each possible way:

var url = $().SPServices.SPGetCurrentSite() + 
                    "/_vti_bin/listdata.svc/"; //responseText=null, status:404
var url = $().SPServices.SPGetCurrentSite();//responseText=null, status:404
var url = "" //responseText=soapresponse above, status:500

Why is this not working??? What am I doing wrong???

1

There are 1 best solutions below

9
AudioBubble On

Can you change your implemetation to something other ?
Your way is very complicated by my opinion. Third party libraries here are unnecessary.
Good way is to use out-of-box REST API or JSOM. It is easy to use.

I see you want to get list item Title field.
Use REST API this way:
http://site url/_api/web/lists/GetByTitle('Test')/items?$select=Title

Here you can find example:
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-lists-and-list-items-with-rest
https://www.c-sharpcorner.com/blogs/retrieve-sharepoint-list-items-using-rest-api

May be you can use for SharePoint 2010:

var myRestApiUrl = _spPageContextInfo.webServerRelativeUrl + "/_vti_bin/ListData.svc/RFCExtract?$select=Title";
var get = function (url) {
    return jQuery.ajax({
        url: url,
        type: "GET",
        processData: false,
        headers: {
            Accept: "application/json;odata=verbose",
        }
    });
};
get(myRestApiUrl)
.then(function(response){
    // TODO: do actions with response

});