Remove duplicates

Discussions about Cross-site Lookup
Locked
User avatar
Jaitsujin
Posts: 7
Joined: Tue Jan 08, 2019

29 Jun 2020

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?

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

29 Jun 2020

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.
Cheers

User avatar
Jaitsujin
Posts: 7
Joined: Tue Jan 08, 2019

01 Jul 2020

Got it. Thank you!

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest