Page 1 of 1

Lookup filter not applied based on parent choice

Posted: 22 Jun 2016
by Jaydius
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";

Re: Lookup filter not applied based on parent choice

Posted: 23 Jun 2016
by Dmitry Kozlov
Hi,

What you want is the default behaviour. So, just click 'Reset' link above the 'Request items' field in the Lookup Manager and save the configuration.

Re: Lookup filter not applied based on parent choice

Posted: 27 Jun 2016
by Jaydius
But I still want to filter by all other choices on the Site dropdown. Was just wondering if there was a way to not filter the equipment and component lists if a specific option on the site dropdown was chosen, e.g. 'All Sites'. If 'Site A' was selected, the filter behaviour would still work, only displaying equipment that is associated with 'Site A'.

Re: Lookup filter not applied based on parent choice

Posted: 28 Jun 2016
by Dmitry Kozlov
I see. Yes, you can ignore particular values from the drop-down:

Code: Select all

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) {
        var filter = facilityId ? "$filter=Site/Id eq " + facilityId + "&" : '';
        return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},Site/Id&$orderby={LookupField}&$expand=Site/Id&" + filter + "$top=30";
    }

    var filter = facilityId ? "$filter=substringof('" + encodeURIComponent(term) + "', {LookupField}) and Site/Id eq " + facilityId + "&" : "$filter=substringof('" + encodeURIComponent(term) + "', {LookupField})&";
    return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},Site/Id&$orderby={LookupField}&$expand=Site/Id&" + filter + "$top=30";
}