Lookup filter not applied based on parent choice

Discussions about Cross-site Lookup
Locked
Jaydius
Posts: 43
Joined: Thu Nov 12, 2015

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

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

23 Jun 2016

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
Posts: 43
Joined: Thu Nov 12, 2015

27 Jun 2016

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

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

28 Jun 2016

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

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests