Trouble Retrieving data

Discussions about Cross-site Lookup
Locked
cwalter2
Posts: 3
Joined: Wed Jul 10, 2019

10 Jul 2019

I have a list with a cross site lookup field looking to another list cross site look up field. My plan is to use the information in Forms Designer with an on change event. Currently it is bringing in an object as undefined. What is the problem with my code?

Here is the cross site look up that I am having a problem with (I bolded the problem item):
function (term, page) {
if (!term || term.length == 0) {
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},PLStatus,Title,PLProjManager/Id&$expand=PLProjManager&$orderby={LookupField} asc&$filter=PLStatus eq 'Active Project'&$top=30";
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},PLStatus,Title,PLProjManager/Id&$expand=PLProjManager&$orderby={LookupField}&$filter=startswith({LookupField}, '" + encodeURIComponent(term) + "') and PLStatus eq 'Active Project'&$top=30";
}

Here is the cross site lookup on the target:
function (term, page) {
var HRCompany = "Our Company Name";
if (!term || term.length == 0) {
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField}&$orderby=Created desc&$filter=CLCompanyCopy eq '"+ encodeURIComponent(HRCompany) + "'&$top=10";
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField}&$orderby={LookupField}&$filter=startswith({LookupField}, '" + encodeURIComponent(term) + "') and CLCompanyCopy eq '"+ encodeURIComponent(HRCompany) + "'&$top=10";
}

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

10 Jul 2019

Dear Walter,
Can you try the following code?

Code: Select all

function (term, page) {
if (!term || term.length == 0) {
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},PLStatus,Title,PLProjManager/Id&$expand=PLProjManager/Id&$orderby={LookupField} asc&$filter=PLStatus eq 'Active Project'&$top=30";
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},PLStatus,Title,PLProjManager/Id&$expand=PLProjManager/Id&$orderby={LookupField}&$filter=startswith({LookupField}, '" + encodeURIComponent(term) + "') and PLStatus eq 'Active Project'&$top=30";
}
Also, make sure the Internal Name of the field you are trying to retrieve is PLProjManager and it's a Lookup/Person.
Cheers

cwalter2
Posts: 3
Joined: Wed Jul 10, 2019

10 Jul 2019

I made the requested changes.

Request Items:

Code: Select all

function (term, page) {
if (!term || term.length == 0) {
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},PLStatus,Title,PLProjManager/Id&$expand=PLProjManager/Id&$orderby={LookupField} asc&$filter=PLStatus eq 'Active Project'&$top=30";
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},PLStatus,Title,PLProjManager/Id&$expand=PLProjManager/Id&$orderby={LookupField}&$filter=startswith({LookupField}, '" + encodeURIComponent(term) + "') and PLStatus eq 'Active Project'&$top=30";
}
To get a picture of what was being returned I made the item format:

Code: Select all

function(item) {
  return '<span class="csl-option">' + item["{LookupField}"] + " - " + item.Title + " " + item.PLProjManager.Id + '</span>'
}
Here is what is looks like:
It returns undefined in the place for item.PLProjManager.Id

User avatar
mnikitina
Posts: 264
Joined: Wed Jun 05, 2019

12 Jul 2019

Dear Walter,

Could you please clarify if the Manager filed is the people picker field or the lookup field.

Thank you!

cwalter2
Posts: 3
Joined: Wed Jul 10, 2019

13 Jul 2019

It is a look up field. I was mistaken earlier. It is returning a number. Which I assume may be the Id on the original list in lieu of the Display Name field I created.

User avatar
mnikitina
Posts: 264
Joined: Wed Jun 05, 2019

16 Jul 2019

Walter,

Please use the below code in Lookup settings.
To get the Title of the lookup field I've replaced Id with Title.

Code: Select all

function (term, page) {
if (!term || term.length == 0) {
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},PLStatus,Title,PLProjManager/Title&$expand=PLProjManager/Id&$orderby={LookupField} asc&$filter=PLStatus eq 'Active Project'&$top=30";
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},PLStatus,Title,PLProjManager/Title&$expand=PLProjManager/Id&$orderby={LookupField}&$filter=startswith({LookupField}, '" + encodeURIComponent(term) + "') and PLStatus eq 'Active Project'&$top=30";
}
Also, you can use this code in JavaScript editor to get the value.

Code: Select all

fd.field('{LookupFieldInternalName}').control('data')['PLProjManager'].Title;

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 9 guests