Page 1 of 1

Filtered lookups

Posted: 09 Mar 2015
by helgigunnar
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";


}

Re: Filtered lookups

Posted: 10 Mar 2015
by Dmitry Kozlov
Please, try to correct the code following way:

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";
}
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.

Re: Filtered lookups

Posted: 13 Mar 2015
by helgigunnar
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)

Re: Filtered lookups

Posted: 14 Mar 2015
by Dmitry Kozlov
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.

Re: Filtered lookups

Posted: 30 Mar 2015
by helgigunnar
Ok, I can easily do that, but the lookup still doesn't work.

Re: Filtered lookups

Posted: 31 Mar 2015
by Dmitry Kozlov
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?