I am trying to get a random list item field from a sharepoint list. but the results return is undefined. The URL of the rest api is correct as i copy and past it directly to the browser it displays correct value.
Please see the code below
window.myFunction = function() {
var randomNumber = Math.floor(Math.random() * 320);
alert('myFunction triggerred' + randomNumber);
//var listRandomURl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Wealoffortune')/items(4)?$select=Title&$top=1";
var listRandomURl = "https://mysite.sharepoint.com/sites/development2/_api/web/lists/GetByTitle('Wealoffortune')/items("+randomNumber+")/Actions";
alert(listRandomURl);
$.ajax({
url: listRandomURl,
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
alert(data.d.results);
}
});
}
fd.spRendered(function () {
fd.control('Button1').onclick = "myFunction();";
});
Also i would like this to be shown in a label not in an alert how do i do that?
/Actions
in your endpoint URL? Also, the item with ID equals torandomNumber
should be present in list then only it will return the results.var listRandomURl = "https://mysite.sharepoint.com/sites/development2/_api/web/lists/GetByTitle('Wealoffortune')/items("+randomNumber+")?$select=Actions";
...3, 4, 6, 7...
, and even if the total number of list items is 320, the top ID would now be 321 (since there is a gap where 5 used to be). List item IDs do not correlate with an indexer into the number of list items in the list.