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.
/lists
part). Try it with value ashttp://myWebSiteSharepoint.com.br/risk/dtm/gd
. Just a note: try avoidingasync:false
wherever possible since it blocks the UI thread and leads to poor performance.