Page 1 of 1

Added lookup column values

Posted: 29 Jun 2019
by Office365Guy
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";
}

Re: Added lookup column values

Posted: 01 Jul 2019
by Nikita Kurguzov
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";
}

Re: Added lookup column values

Posted: 08 Jul 2019
by Office365Guy
As always, perfect. This will help a ton.

Thanks again.