Lookup filter not applied based on parent choice

rss

Posted by Jaydius - Jun 22 ’16 at 04:07

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

 

}

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 8 years 3 months 29 days
    #1 by Dmitry Kozlov Jun 23 ’16 at 04:03

    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.

  • Jaydius
    Member
    Member for: 6 years 2 months 9 days
    #2 by Jaydius Jun 27 ’16 at 10:37

    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'.

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 8 years 3 months 29 days
    #3 by Dmitry Kozlov Jun 28 ’16 at 07:59

    [#2]: I see. Yes, you can ignore particular values from the drop-down:

    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";
    }
    
Displaying 1 to 3 of 3 messages