Use Cross-site lookup on a lookup column in other list "Loading failed"

Discussions about Cross-site Lookup
Locked
ragesoft
Posts: 50
Joined: Fri Feb 23, 2018

04 Jun 2018

Hi,
i have a question related to the use of cross-site-lookup and lookup columns to sort/display the value.

i've got 3 lists:
List A holds basic Data
- Item A1 (Title: "Basic 1")
- Item A2 (Title: "Basic 2")
- Item A3 (Title: "Basic 3")
List B holds additional Data to entries in List A as a lookup column name "LookupA"" (one-to-many)
- Item B1-A1 (Title: "Update 1", LookupA: "Item A1")
- Item B2-A1 (Title: "Update 2", LookupA: "Item A1")
- Item B3-A2 (Title: "Update 1", LookupA: "Item A2")
List C holds information to items in List B with a column "LookupB" (one-to-many)
- Item C1
- Item C2
- Item C3

With normal Lookup i will see two times "Update 1" in the dropdown and no additional information, what is the Basic item reletead...

Now i want to use the cross-site lookup in "List C" to manage a better display of the items from list B like "Item A1 - Update 1":
As lookup field i select "Title" form list B.
Request items:

Code: Select all

function (term, page) {
  if (!term || term.length == 0) {
    return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},LookupA&$orderby=LookupA&$top=10";
  }
  return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},LookupA&$orderby=LookupA&$filter=startswith(LookupA, '" + encodeURIComponent(term) + "')&$top=10";
}
Item format:

Code: Select all

function(item) {
  return '<span class="csl-option">' + item.LookupA + ' - ' + item["{LookupField}"] + '</span>'
}
I receive the "Loading failed" error :(

How to setup the request and format to use lookup-column-values???
Something like "item.LookupA.Value" ??

How to sort by more than one columen (e.g.: LookupA, Title)?

Thx for your help :)

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

04 Jun 2018

Dear ragesoft,
When working with Lookup fields, it's important to not only retrieve specific values, but also to expand them, since they are stored in another list. Code like this for Request items:

Code: Select all

function (term, page) {
  if (!term || term.length == 0) {
    return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},LookupA/ID,LookupA/Title&$expand=LookupA/ID,LookupA/Title&$orderby=LookupA/ID&$top=10";
  }
  return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},,LookupA/ID,LookupA/Title&$expand=LookupA/ID,LookupA/Title&$orderby=LookupA/ID&$filter=startswith(LookupA, '" + encodeURIComponent(term) + "')&$top=10";
}
And like this for Item format:

Code: Select all

function(item) {
  return '<span class="csl-option">' + item.LookupA.Title + ' - ' + item["{LookupField}"] + '</span>'
}
Should work.
Cheers

ragesoft
Posts: 50
Joined: Fri Feb 23, 2018

06 Jun 2018

OH!

$expand did the job :)

I didnt found it in docu. it was hidden insed the code snippets :D

thx a lot!

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 6 guests