Hi,
We recently had a requirement where we wanted to mark list item as read when they are opened (DispForm.aspx).
For this we added a Yes/No (checkbox) field to the List.
Opened the DispForm.aspx for editing and added a Content Editor web part there.
Uploaded a text file having following script in one of the document libraries.
</pre>
_spBodyOnLoadFunctionNames.push("updateListItem");
function updateListItem() {
var siteUrl = window.location.protocol + "//" + window.location.host;
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('Notifications');
JSRequest.EnsureSetup();
//Get a query string parameter called Id. i.e - "page.aspx?Id=11" will return 11
var itemId = JSRequest.QueryString["ID"];
this.oListItem = oList.getItemById(itemId);
oListItem.set_item('MarkAsRead', true);
oListItem.update();
clientContext.executeQueryAsync(
Function.createDelegate(this, this.onQuerySucceeded),
Function.createDelegate(this, this.onQueryFailed)
);
}
function onQuerySucceeded() {
alert('Item updated!');
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
<pre>
And refered that txt file in our content web editor web part.

Hope it helps.






