1

Is there any way to count the number of times a list item has been accessed. I have a list of type announcements and we post a handful of announcements to our intranet home page and expect folks to open the articles and read through.

Trying to gauge their interest on each article though this process.

GetUsageData or a custom httphandler, can any one advise on the approach.

Environment is SharePoint 2013 on prem.

  • Are the articles in a sharepoint page? or outside the sharepoint enviornment – Swayam Siddha Jul 7 '17 at 6:19
0

Maybe you can have a JSOM/Rest function that is embedded into the target page that the hyperlink ( provided its in sharepoint ). The function pulls the current url, and update a ViewCount column against the url entry.

enter image description here

The code will be something like the below, I haven't run it, Please validate before trying-

var siteUrl = '/sites/MySiteCollection';
var url = windows.location.href;
function updateListItem() {
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('Announcements');

 var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><Query><Where><eq>' + 
    '<FieldRef Name=\'Link\'/><Value Type=\'hyperlink\'>'+url+'</Value>' + 
    '</eq></Where></Query><RowLimit>50</RowLimit></View>');

this.collListItem = oList.getItems(camlQuery);
oListItem.set_item('ViewCount', this.collListItem[0]["ViewCount"] + 1); //validate if this works

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());
}

Source - MSDN operations on a list using JSOM

  • So I have created a webpart and added that to Post.aspx page and that keeps count of the visits for each article on a list column called ViewCount. Your comment helped me take this route. – UP26 Jul 13 '17 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.