Nderon Hyseni Nderon Hyseni - 3 months ago 6x
Javascript Question

how to get a value from a Sharepoint list with javascript

i have the following code:

window.onload = function () {
var setTime = /*this should go the number*/
var fiveMinutes = 60 * setTime;
display = document.querySelector('#timer2');
startTimer(fiveMinutes, display);

what i want is
var setTime
to get the value or retrieve from list with column named
the datatype for
is number
thanks all!


To communicate with SharePoint you need to use the JavaScript client object model as follows:

 var ctx = new SP.ClientContext.get_current();
 var web = ctx.get_web();
 var listCollection = web.get_lists();
 var list = listCollection.getByTitle(NameOfYourList);
 var listItem = list.getItemById(TheItemID);

 context.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

and then

 function onQuerySucceeded() {
 var setTime =  listItem.get_item('testval');
 //continue your work

 function onQueryFailed(sender, args) {

Remember to reference SP.js script tag:

 <SharePoint:ScriptLink Name="SP.js" runat="server" OnDemand="true" Localizable="false" ></SharePoint:ScriptLink>