Lookup with other columns

Discussions about Cross-site Lookup
Locked
Mapleleaf
Posts: 29
Joined: Tue Oct 25, 2016

16 Nov 2016

I have a Lookup-filed with the code beneeth. It works fine. Problem is, when "anothercolumn" is a lookup-field to another list in the target list istself. Then the lookup shows the text "object". Is it possible to display the text of lookup-field as column?



function (term, page) {

if (!term || term.length == 0) {

return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},anothercolumn1,anothercolumn2&$orderby=Created desc&$top=10";

}

return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},anothercolumn1,anothercolumn2&$orderby={LookupField}&$filter=startswith({LookupField}, '" + encodeURIComponent(term) + "')&$top=10";

}

2. Add the fields to the item format function:

function(item) {

return '<span class="csl-option">' + item["{LookupField}"] + ' ' + item['anothercolumn1'] + ' ' + item['anothercolumn2'] + '</span>'

}

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

17 Nov 2016

Hi,

The code should be:

Code: Select all

Request items:

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

Code: Select all

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

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 15 guests