I have the following code:

window.onload = function () {
    var setTime = // i dont know what to do here
    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 testval the datatype for testval is number.


You can reference snippet below for getting list value through JSOM

function retrieveListItems() {
        targetList = list.getByTitle("your list name"); //get the list details
        var camlQuery = new SP.CamlQuery(); //initiate the query object
        '<View><Query><Where><Contains><FieldRef Name=\'Title\'/>' +
        '<Value Type=\'Text\'>V</Value></Contains></Where></Query>' +
        itemColl = targetList.getItems(camlQuery);
        //returns the item collectionbased on the query
        context.executeQueryAsync(retrieveListItemsSuccess, retrieveListItemsFail);

function retrieveListItemsSuccess() {
var listItemEnumerator = itemColl.getEnumerator();
 while (listItemEnumerator.moveNext()) {
 var oListItem = listItemEnumerator.get_current();
 var listDetails =oListItem.get_item('Title') ;

 // This function is executed if the above call fails
 function retrieveListItemsFail(sender, args) {
    alert('Failed to get list items. Error:' + args.get_message());

I do it also most of the time with REST (ajax) like this:

<script type="text/javascript">

    $(document).ready(function() {
        // Rest URL
        var requestUri = "/_api/lists/getbytitle('MyList')/items";

                url: requestUri,
                type: "GET",
                headers: { "ACCEPT": "application/json;odata=verbose" },
                success: function (data) {
                    $.each(data.d.results, function (i, item){
                        var title = item.Title;

                        // Do something                     

                error: function () {
                    alert("Something went wrong");


Hope it helped!


You can use rest api to get this

make a request to this page, it will return items in the list

http://somesharepointsite/sites/viewstyle/_api/Web/Lists/GetByTitle('Employee List')/items?$select=To/Title,To/ID&$expand=To"

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.