Page 1 of 1

Remove duplicates

Posted: 29 Jun 2020
by Jaitsujin
Hi,

I was wondering if something like the following is possible?

Code: Select all

function (term, page) {
  if (!term || term.length == 0) {
  var list = "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField}&$orderby={LookupField}&$top=5";
  var unique = [];
  $.each(list, function(index, value){
        if(unique.indexOf(value.Title) === -1){
            unique.push(value.Title);
        }
    });
    return unique;
  }
  return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField}&$orderby={LookupField}&$filter=startswith({LookupField}, '" + encodeURIComponent(term) + "')&$top=5";
}
This is obviously wrong, but i just mean in terms of the logic? Is something similar supported?

Re: Remove duplicates

Posted: 29 Jun 2020
by Nikita Kurguzov
Dear Jaitsujin,
All what is suppored is based on SharePoint's OData queries, and unfortunately, I don't think it's possible to filter out duplicates in this way - https://docs.microsoft.com/en-us/sharep ... t-requests

Plus, if there are duplicate values in the original list - it could be a problem for other use cases, such as cascading dropdowns (or even the lookup's URL leading to an incorrect item). It's best to keep the source list for the lookup clear of duplicates.

Re: Remove duplicates

Posted: 01 Jul 2020
by Jaitsujin
Got it. Thank you!