Trouble Retrieving data
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";
}
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";
}
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Dear Walter,
Can you try the following code?
Also, make sure the Internal Name of the field you are trying to retrieve is PLProjManager and it's a Lookup/Person.
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";
}
Cheers
I made the requested changes.
Request Items:
To get a picture of what was being returned I made the item format:
Here is what is looks like:
It returns undefined in the place for item.PLProjManager.Id
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";
}
Code: Select all
function(item) {
return '<span class="csl-option">' + item["{LookupField}"] + " - " + item.Title + " " + item.PLProjManager.Id + '</span>'
}
It returns undefined in the place for item.PLProjManager.Id
Walter,
Please use the below code in Lookup settings.
To get the Title of the lookup field I've replaced Id with Title.
Also, you can use this code in JavaScript editor to get the value.
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";
}
Code: Select all
fd.field('{LookupFieldInternalName}').control('data')['PLProjManager'].Title;
-
- Information
-
Who is online
Users browsing this forum: No registered users and 7 guests