I am using REST API to update in custom list of SharePoint Server. It is a dashboard and displays result as per logged in user. Is it possible to update 1st row always using REST API irrespective of ID of row? Rest API is updating table but I want to update 1st row always.
CODE:
function UpdatePendingListItem(value)
{
$.ajax
({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('<LIST_NAME>')/items(<ITEM_ID>)", // list item ID
type: "POST",
data: JSON.stringify
({
__metadata:
{
type: "SP.Data.<LIST_NAME>ListItem"
},
COLUMN_NAME1:value,
COLUMN_NAME2: loginName
}),
headers:
{
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"IF-MATCH": "*",
"X-HTTP-Method": "MERGE"
},
async: false,
success: function(data, status, xhr)
{
},
error: function(xhr, status, error)
{
}
});
}
**code to call function and update:**
getListItemsForView(_spPageContextInfo.webAbsoluteUrl,'<list_name>','<View_name>')
.done(function(data)
{
var items = data.d.results;
console.log("Waiting For Approval=" +data.d.results.length);
//for(var i = 0; i < items.length;i++) {
// console.log(items[i].Title);
//}
if(DashboardItemCount==0)
{
CreatePendingListItem(data.d.results.length);
}
else
{
UpdatePendingListItem(data.d.results.length);
}
})
.fail(
function(error){
console.log(JSON.stringify(error));
});
data.d.results[0].Id
as ID of 1st item(from the results you are getting from your REST call). – Ganesh Sanap Jul 26 at 12:43