Implementing Marking Item as Read functionality for list item in SharePoint 2013.

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.


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

One thought on “Implementing Marking Item as Read functionality for list item in SharePoint 2013.”

  1. Hi,
    We have a notifications list same like your requirement, but we need to implement a functionality when many users access the same list item, it should be set as ‘read’ for each user when he/she opens the item. is this possible?

    Like

Share your thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s