6

I am working on a custom list inside our SharePoint on-premises 2013. i created the custom list to store the users who access a discussion board items, by following this approach:-

1- Inside the discussion board's flat.aspx page, i entered the following javascript which will add a new item inside the cusotm list, by passing the item title as follow:-

2- then i am interested in knowing the number of users who accessed a specific discussion board item. so inside my list view i chose to do the follow 2 settings:-

  • group the item by title
  • show the count

As follow:-

enter image description here

3- so my list view will show the item title + the number of users who accessed the item, as follow:-

enter image description here

but the only issue i am facing with the above appraoch, is that when the same user access the same discussion board item, 2 items will be added inside the custom list, and the 2 items will have the same title & created by.

but i want the counter which is shown beside the title inside my list view, to NOT count any duplicate items. where duplicates in my case, is any item inside the cusotm list which have the same Created-by & title. so is this something i can achieve ?

  • Is there any specific reason to store duplicate values? – Anil Pal Jul 3 '18 at 11:23
  • @AnilPal yes we need duplicates to be stored... so we can know the users who access the items... but for the count we do not want duplicates to be counted.. so for certain item i can know that 20 unique users access the item,, but inside the list we need to know that certain user access the same item 5 times for example.. – john Gu Jul 3 '18 at 13:09
3
+25

Instead of creating an item every time, add a field to count the number of times a given user has visited it. Then each time they visit it, increment that counter by 1.

Essentially, when the flat.aspx opens, perform a query to see if the current user has already visited it (store their unique id or something in the record itself), and if so update the count. If not, create a new record with count = 1.

  • we need duplicates to be stored... so we can know the users who access the items... but for the count we do not want duplicates to be counted.. so for certain item i can know that 20 unique users access the item,, but inside the list we need to know that certain user access the same item 5 times for example.. – john Gu Jul 4 '18 at 23:51
  • My suggestion accomplishes both. Each record indicates at least 1 visit, or "unique visitors". Subsequent visits or "how many times the same user accesses the same item" is tracked via the counter. – Chad Jul 5 '18 at 14:47
  • ok i got your point,, will modify my script and test how things will go.. – john Gu Jul 6 '18 at 13:33

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.