Added lookup column values

Discussions about Cross-site Lookup
Locked
Office365Guy
Posts: 21
Joined: Sun Feb 24, 2019

29 Jun 2019

The first CSL, Bill_x0020_To_x0020_Contact, has the additional column "Client", a CSL field. The second CSL needs to use the "Client ID" from the first CLS's client lookup field as the filter. Can't seem to get this to work. Please help.

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



function (term, page) {
if (!term || term.length == 0) {
var clientId = fd.field('Bill_x0020_To_x0020_Contact').control('data')['Client'];
if (!clientId) {
clientId = 0;
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},Street,City,State,Zip&$orderby={LookupField}&$filter=ID eq " + clientId + "&$top=10";
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},Street,City,State,Zip&$orderby={LookupField}&$filter=startswith({LookupField}, '" + encodeURIComponent(term) + "') and ID eq " + clientId + "&$top=10";
}

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

01 Jul 2019

Dear Office365Guy,
Please, change the code for Bill_x0020_To_x0020_Contact to this:

Code: Select all

function (term, page) {
if (!term || term.length == 0) {
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},WorkPhone,CellPhone,Email,Client/Id&$expand=Client&$orderby={LookupField}&$top=10";
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},WorkPhone,CellPhone,Email,Client/Id&$expand=Client&$orderby={LookupField}&$filter=startswith({LookupField}, '" + encodeURIComponent(term) + "')&$top=10";
}
Then, you should be able to get value of lookup like this:

Code: Select all

function (term, page) {
  var clientId = fd.field('Bill_x0020_To_x0020_Contact').control('data').Client.Id;
  if (!clientId) {
    clientId = 0;
  }
  if (!term || term.length == 0) {
    return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},Street,City,State,Zip&$orderby={LookupField}&$filter=ID eq " + clientId + "&$top=10";
  }
  return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},Street,City,State,Zip&$orderby={LookupField}&$filter=startswith({LookupField}, '" + encodeURIComponent(term) + "') and ID eq " + clientId + "&$top=10";
}
Cheers

Office365Guy
Posts: 21
Joined: Sun Feb 24, 2019

08 Jul 2019

As always, perfect. This will help a ton.

Thanks again.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 3 guests