Filtered lookups
-
- Posts: 3
- Joined: Mon Mar 09, 2015
Dear All,
I'm trying to filter a lookup based, where I have a supplier Custom List and a certificate Document Library. The supplier list has a lookup filed to the certificate library, e.g List: Certificates and Field:Certificates Number. I have tried changing back and forth, but it either just says "searching" or it provides me with all the values. I checked what I was getting by putting the Supplier/Id in the Item format and it resulted in unassigned. Here is the code, any suggestions are much appreciated and please feel free to ask:
function (term, page) {
var CompanyId = fd.field('Title').value();
if (!CompanyId) {
CompanyId = 0;
}
if (!term || term.length == 0) {
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},Supplier/Id&$orderby={LookupField} asc&$expand=Supplier/Id&$filter=Supplier/Id eq CompanyId&$top=10";
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField}&$orderby={LookupField} asc&$filter=startswith({LookupField}, '" + encodeURIComponent(term) + "')&$top=10";
}
I'm trying to filter a lookup based, where I have a supplier Custom List and a certificate Document Library. The supplier list has a lookup filed to the certificate library, e.g List: Certificates and Field:Certificates Number. I have tried changing back and forth, but it either just says "searching" or it provides me with all the values. I checked what I was getting by putting the Supplier/Id in the Item format and it resulted in unassigned. Here is the code, any suggestions are much appreciated and please feel free to ask:
function (term, page) {
var CompanyId = fd.field('Title').value();
if (!CompanyId) {
CompanyId = 0;
}
if (!term || term.length == 0) {
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},Supplier/Id&$orderby={LookupField} asc&$expand=Supplier/Id&$filter=Supplier/Id eq CompanyId&$top=10";
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField}&$orderby={LookupField} asc&$filter=startswith({LookupField}, '" + encodeURIComponent(term) + "')&$top=10";
}
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
Please, try to correct the code following way:
If it doesn't work, open the browser console and check whether errors or notifications appear there when you try to search a lookup value on the form.
Code: Select all
function (term, page) {
var CompanyId = fd.field('Title').value();
if (!CompanyId) {
CompanyId = 0;
}
if (!term || term.length == 0) {
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},Supplier/Id&$orderby={LookupField} asc&$expand=Supplier/Id&$filter=Supplier/Id eq '" +
CompanyId +
"'&$top=10";
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField}&$orderby={LookupField} asc&$filter=startswith({LookupField}, '" + encodeURIComponent(term) + "')&$top=10";
}
-
- Posts: 3
- Joined: Mon Mar 09, 2015
I got the following error message:
https://services.spform.com/crosssitelo ... e_en_us.js Failed to load resource: the server responded with a status of 404 (Not Found)
https://services.spform.com/crosssitelo ... e_en_us.js Failed to load resource: the server responded with a status of 404 (Not Found)
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
Please, ignore the error, it doesn't affect the Cross-site Lookup functionality. The default language is English, so there is no a separate language file for English.
-
- Posts: 3
- Joined: Mon Mar 09, 2015
Ok, I can easily do that, but the lookup still doesn't work.
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
Could you open the browser console (F12) and expand the dropdown control, Next, start typing. Do errors or notifications appear in the console? How many items are in your source list?
-
- Information
-
Who is online
Users browsing this forum: No registered users and 20 guests