I have a list column which I want to update using JSOM on button click. Here's my code -
function updateListItem() {
var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('Topics');
this.oListItem = oList.getItemById(20);
clientContext.load(oListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() {
var oldData = oListItem.get_item('ViewCount');
var newData = parseInt(oldData) + 1;
alert(newData);
oListItem.set_item('ViewCount', newData);
oListItem.update();
clientContext.executeQueryAsync(Function.createDelegate(this, this.onItemUpdated), Function.createDelegate(this, this.onQueryFailed));
}
function onItemUpdated() {
alert('Item has been updated!');
}
function onQueryFailed(sender, args) {
alert('Request failed.');
}
But, it's not working.