0

i'm new to SharePoint so I might be asking something silly, or maybe doing silly mistakes, but i've looked it up all over and couldn't find a solution.

So Basically I want to access a Sharepoint list and return the values from a single column:

<html>
<head>
    <script language='javascript' type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
    <script language='javascript' type='text/javascript' src="http://myWebSite.com/risk/dtm/JS/jquery.SPServices-2014.01.min.js"></script>
    <script language='javascript' type='text/javascript' src="http://myWebSite.com/risk/dtm/JS/sputility.min.js"></script>
    <title>Test sharepoint</title>
</head>
<body>

    <div id='result'></div>



    <script>
    $(document).ready(function(){

        var query = '<Query>'+
                        '<Where>'+
                            '<And>'+
                                '<Eq>'+
                                    '<FieldRef Name="Ambiente"/><Value Type="Text">SAS</Value>'+
                                '</Eq>'+
        /*
                                '<Neq>'+
                                    '<FieldRef Name="IsOldRequest"/><Value Type="Text">Y</Value>'+
                                '</Neq>'+
        */
                            '</And>'+
                        '</Where>'+
                    '</Query>';

        var view = '<ViewFields>'+
                    '<FieldRef Name="Title" />'+
                  '</ViewFields>';
        var htmlTable='';
        var TrainingTitle;
        var RequestStatus;
        var Created;
        var RequestorName;
        var Deployement;
        $().SPServices({
                    operation: "GetListItems",
                    async: false,
                    webURL: 'http://myWebSiteSharepoint.com.br/risk/dtm/gd/Lists/grupos/AllItems.aspx?ShowInGrid=True&View=%7BEC1106D7%2DDCD4%2D4425%2DBC49%2DFEDCCD55AF8A%7D&InitialTabId=Ribbon%2EList&VisibilityContext=WSSTabPersistence',
                    listName: "Grupos e RDOs",
                    CAMLViewFields: view ,
                    CAMLQuery : query ,
                    completefunc: function (xData, Status) {
                        console.log(xData);
                        console.log(Status);
                        var totalRows = parseInt($(xData.responseXML).SPFilterNode("rs:data").attr("ItemCount"));

                        if(totalRows > 0)
                        {                       
                            $(xData.responseXML).SPFilterNode('z:row').each(function()
                            {
                                TrainingTitle = $(this).attr("ows_TrainingTitle");
                                if(TrainingTitle === undefined)
                                    TrainingTitle = '';

                                RequestStatus = $(this).attr("ows_RequestStatus");
                                if(RequestStatus === undefined)
                                    RequestStatus ='';

                                Created = $(this).attr("ows_Created");
                                if(Created === undefined)
                                    Created ='';

                                RequestorName = $(this).attr("ows_RequestorName");
                                if(RequestorName === undefined)
                                    RequestorName= '';

                                Deployement = $(this).attr("DeployementDate");
                                if(Deployement === undefined)
                                    Deployement ='';
                // Store data in variable once all data in stored append it to table                    
                                htmlTable+="<tr><td>"+RequestStatus +"</td><td>"+TrainingTitle +"</td><td>"+Created+"</td><td>"
                                            +RequestorName +"</td><td>"+ Deployement +"</td></tr>";                                 
                            });
                            //$("#exportToExcel").append(htmlTable);

                        }else{
                            console.log("rows less than 0");
                            console.log(totalRows);
                        }
                    }
        }); 
    });
    </script>
</body>
</html>

So, with my console.logs I got the following results:

xData: full javascript object, with 200 status and the following responseText:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns:o="urn:schemas-microsoft-com:office:office" lang="pt-br" dir="ltr">
<head><meta http-equiv="X-UA-Compatible" content="IE=8" /><meta name="GENERATOR" content="Microsoft SharePoint" /><meta name="progid" content="SharePoint.WebPartPage.Document" /><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta http-equiv="Expires" content="0" /><title>
    Grupos e RDOs - Todos os Itens
</title><link rel="stylesheet" type="text/css" href="/risk/dtm/gestaodedados/_themes/1/search-EB0BE372.css?ctag=2"/>
<link rel="stylesheet" type="text/css" href="/risk/dtm/gestaodedados/_themes/1/corev4-AB0302A5.css?ctag=2"/>

    <script type="text/javascript">
    var _fV4UI = true;
    </script>
    <script type="text/javascript">
// <![CDATA[
document.write('<script type="text/javascript" src="/_layouts/1046/init.js?rev=M1qgSOO%2Bkv9U8HtiTmhOpg%3D%3D"></' + 'script>');
document.write('<script type=",

It cuts the end, but it seems it is actually connecting to the list, I also got a 200 http code in the list.

Now for the function Status I got: ParseError.

And for the totalRows I got: NaN.

I feel like the parseError is where the problem is, but I can't figure out what I did wrong.

ps: I changed some of the urls for security reasons, but they're working just fine.

  • 1
    webURL is the URL of the SharePoint web (minus the/lists part). Try it with value as http://myWebSiteSharepoint.com.br/risk/dtm/gd. Just a note: try avoiding async:false wherever possible since it blocks the UI thread and leads to poor performance. – Akhoy Aug 24 '18 at 14:09
  • @Akhoy Thank you for the answer, indeed the change made it better since now I get a responseXML in the javascript object. But i'm getting the myWebSiteSharepoint.com.br/risk/dtm/gd/_vti_bin/Lists.asmx HTTP POST 500 text/xml in my list, it says internal server error. Maybe it means I cant access it from a web page? – Felipe Oliveira Aug 24 '18 at 14:27
  • Now i'm getting the "one or more fields are not installed correctly" despite i'm using internal field names from the url – Felipe Oliveira Aug 24 '18 at 17:47
  • Something is wrong with your CAML query then. Try executing it in a CAML query builder and see if it returns results. u2u.be/software – Akhoy Aug 25 '18 at 5:18
1

Since there is only 1 condition no need for <And> in CAML query. Update caml query like below,

 var query = '<Query>'+
                '<Where>'+
                        '<Eq>'+
                            '<FieldRef Name="Ambiente"/><Value Type="Text">SAS</Value>'+
                        '</Eq>'+
                '</Where>'+
            '</Query>';

Update your CAMLViewFields ,

var view = '<ViewFields>'+
                    '<FieldRef Name="Title" />'+
                    '<FieldRef Name="TrainingTitle" />'+
                    '<FieldRef Name="RequestStatus" />'+
                    '<FieldRef Name="Created" />'+
                    '<FieldRef Name="RequestorName" />'+
                    '<FieldRef Name="DeployementDate" />'+
                  '</ViewFields>';

And also update the DeployementDate retrieval like below,

Deployement = $(this).attr("ows_DeployementDate");

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.