Domanda

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.

È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top