Lookup with other columns
Posted: 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>'
}
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>'
}