0

Trying to figure out a way to

Create a list of duplicate list items based on a column contained in such a list. In my example, it is the title column.

First, I was thinking that I could create a group view, but the issue with that is that it also displays items that are not duplicates.

I was thinking that SPServices could be helpful, but I can't figure out a way to display only items that are duplicate. Any assistance would be greatly appreciated.

1 Answer 1

0

Note:

in June 2017, Microsoft disabled the use of JavaScript in a Calculated Column

That means given answers may not apply for newer SharePoint versions

For long explanation and work arounds see:
June 13th 2017 Microsoft blocked handling HTML markup in SharePoint calculated fields - how to get the same functionality back


**Original answer:**
  • You want to record the Title for each displayed row
  • then after all are displayed, hide the ones not having dublicate titles

Client Side Rendering or a jQuery script would be the obvious solutiuon.

Alternative is to jam that code into every ListItem as a Calculated Column.

Biggest benefit, it just executes anywhere it is displayed, no need for loading jQuery, no need for setting JSLinks on every webpart.

Paste the Formula in a Calculated Column, set datatype to Number and include it as last column in a View:

="<img  src=/_layouts/images/blank.gif onload=""{"
&"var rowvalue='count_" & [Title] & "'"
&",counters=window.counters=window.counters||{};"
&"var TR=this;while(TR.tagName!='TR'){TR=TR.parentNode}"
&"counters[rowvalue]=counters[rowvalue] || 0;"
&"counters[rowvalue]++;"
&"_spYield(function(){"
&"  TR.style.display=counters[rowvalue]>1 ? 'table-row' : 'none'; "
&"},1);"
&"}"">"
  • Each item displays a blank IMG to trigger JavaScript code (the SCRIPT tag is disabled by Microsoft)
  • You can then built a JavaScript variable with the value you want to check doubles for

Since this code is always executed for every ListItem we need some special bookkeeping of Global variables

  • we check if a Global variable (object) exists, use it or declare it (once) as a new object
  • we check if the value exists in the global object (a previous occurence) or set the counter to 0
  • then always add 1 to the count

At this stage you could hide double values if the counter is >1 .. but you want the reverse, so it is essential we count all items first.

  • _spYield (declared in SP.js, but you won't find any blogs or documentation) makes JavaScript execution wait (something not possible out of the box with JavaScript)

We need this wait/delay because IMGs are loaded async, thus this code as well and we want to make sure all ListItems are processed/counted.. a yield/Wait of 1 millisecond seems to be enough

So once all ListItems are counted they execute their own function

  • the executed function sets the display based on the counter (for that rowvalue).

You could also not hide rows add apply coloring here:

&"  TR.style.bacgrkound=counters[rowvalue]>1 ? 'lightcoral' : 'beige'; "

.

There are some Pros & Cons to this method. Read: https://www.365csi.nl/vm365com/#/How

iCC

3
  • Danny, thanks so much for this idea. I had not even heard for this trick before. Unfortunately, the solution produces unreliable results. In some instances, it will show only the duplicate "Title" entries, but in other instances, it shows rows with "Titles" that do not have a duplicate. It is rather odd. Have you had any experience with this not operating as intended?
    – user63482
    Commented Jan 17, 2017 at 20:12
  • This type of code injection is difficult to debug. Are you displaying ALL items? The default limit is 30. You can add a line &"console.log(rowvalue,counters[rowvalue]);" just before the _spYield line to trace whats going on. And try increasing that 1 millisecond, maybe the IMGs are loading too slow. You want to execute this function AFTER all items are displayed Commented Jan 17, 2017 at 20:18
  • Better manageable is the CSR/JSLink solution where you proces the Items in the OnPostRender method. Use the Chrome Cisar plugin to easily develop CSR scripts. Commented Jan 17, 2017 at 20:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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