Filtered lookups
Posted: 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";
}
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";
}