Filtered lookups

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
helgigunnar
Posts: 3
Joined: Mon Mar 09, 2015

09 Mar 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";


}

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

10 Mar 2015

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.

helgigunnar
Posts: 3
Joined: Mon Mar 09, 2015

13 Mar 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)

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

14 Mar 2015

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.

helgigunnar
Posts: 3
Joined: Mon Mar 09, 2015

30 Mar 2015

Ok, I can easily do that, but the lookup still doesn't work.

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

31 Mar 2015

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?

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 20 guests