Lookup filter not applied based on parent choice
Posted: 22 Jun 2016
I have two plumsail lookup dropdowns in a form (Equipment, Components), which are currently being filtered based on a parent choice (Site). What im wanting to do is to have a choice in the Site dropdown, that when chosen will not filter the child dropdowns, e.g. 'All Sites' as a choice in the Site dropdown would show all items in the equipment list, irrespective of Site. The current code is as below:
Equipment Dropdown:
function (term, page) {
// Getting the selected site
var facilityId = fd.field('Site').value();
if (!facilityId) {
facilityId = 0;
}
// Filtering by the selected site
if (!term || term.length == 0) {
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},Site/Id&$orderby={LookupField}&$expand=Site/Id&$filter=Site/Id eq " + facilityId + "&$top=30";
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},Site/Id&$orderby={LookupField}&$expand=Site/Id&$filter=substringof('" + encodeURIComponent(term) + "', {LookupField}) and Site/Id eq " + facilityId + "&$top=30";
Equipment Dropdown:
function (term, page) {
// Getting the selected site
var facilityId = fd.field('Site').value();
if (!facilityId) {
facilityId = 0;
}
// Filtering by the selected site
if (!term || term.length == 0) {
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},Site/Id&$orderby={LookupField}&$expand=Site/Id&$filter=Site/Id eq " + facilityId + "&$top=30";
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},Site/Id&$orderby={LookupField}&$expand=Site/Id&$filter=substringof('" + encodeURIComponent(term) + "', {LookupField}) and Site/Id eq " + facilityId + "&$top=30";