2

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.

2

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
        camlQuery.set_viewXml(
        '<View><Query><Where><Contains><FieldRef Name=\'Title\'/>' +
        '<Value Type=\'Text\'>V</Value></Contains></Where></Query>' +
        '<RowLimit>10</RowLimit></View>'
     );
        itemColl = targetList.getItems(camlQuery);
        //returns the item collectionbased on the query
        context.load(itemColl);
        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());
}
2

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";

            $.ajax({
                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");
                }                     
            });                    
    });

</script>

Hope it helped!

1

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.