Description:
I am implementing a lookup to populate a dropdown based on specific criteria, but it is not working as expected.
Criteria for Populating the Dropdown:
- The dropdown should display only those
SchemeCode
values where:- The status is "Released."
- The SchemeCategory matches the value selected by the user in another dropdown.
- Scheme visibility rules:
- Global Schemes → If a scheme exists in Prm
SchemeTable
but has no entry in PrmRegionScheme
, it should be shown (✅ Allowed, but not duplicated). - Region-Specific Schemes → If a scheme exists in Prm
RegionScheme
, it should be shown only if assigned to the user’s region (✅ Show). - Multi-Region Schemes → If a scheme is assigned to multiple regions, it should be visible for its assigned regions only (✅ Allowed, but not duplicated).
- Exclude Other Region Schemes → If a scheme exists only for other regions and not for the user’s region, it should NOT be shown (❌ Exclude).
- A scheme assigned exclusively to another region (e.g., if
S4
is assigned only to 'DEL', it should not be visible in 'KAR').
- Global Schemes → If a scheme exists in Prm
Issue:
While most of the logic is working correctly, the problem arises when a scheme is assigned to multiple regions—it does not appear in the dropdown at all.
What I Did:
- Implemented a lookup function to filter schemes based on the above criteria.
- Ensured schemes assigned to a specific region are visible only within that region.
- Considered creating a separate table to store region-scheme mappings for filtering.
-
public void SchemeLookup(FormStringControl _ctrl) { PRMUserSetup prmUserSetup; PRMRegion_Branch prmRegionBranch; PRmRegion prmRegion; Query query = new Query(); QueryBuildDataSource qbdsScheme, qbdsRegion,qbdsExclude; QueryBuildRange qbrRegion; SysTableLookup sysTableLookup; str userSite, userRegionName, userRegionCode; select firstonly InventSiteId from prmUserSetup where prmUserSetup.UserId == curUserId(); if (!prmUserSetup) return; userSite = prmUserSetup.InventSiteId; select firstonly Name from prmRegionBranch where prmRegionBranch.Code == userSite; if (prmRegionBranch) { userRegionName = prmRegionBranch.Name; select firstonly RegionCode from prmRegion where prmRegion.REGIONNAME == userRegionName; if (prmRegion) userRegionCode = prmRegion.RegionCode; } qbdsScheme = query.addDataSource(tableNum(PRMSchemeTable)); qbdsRegion = qbdsScheme.addDataSource(tableNum(PrmRegionScheme)); qbdsRegion.joinMode(JoinMode::OuterJoin); qbdsRegion.relations(false); qbdsRegion.addLink(fieldNum(PrmRegionScheme, SchemeCode), fieldNum(PRMSchemeTable, SchemeCode)); qbdsScheme.addRange(fieldNum(PRMSchemeTable, Scheme_Category)).value(queryValue(PrmCustomerSchemeEntry.Scheme_Category)); qbdsScheme.addRange(fieldNum(PRMSchemeTable, SchemeStatus)).value(queryValue(PrmSchemeStatus::Release)); if (userRegionCode) { qbrRegion = qbdsRegion.addRange(fieldNum(PrmRegionScheme, RegionCode)); qbrRegion.value(SysQuery::value(userRegionCode) + " || " + SysQuery::valueEmptyString()); } else { qbdsRegion.addRange(fieldNum(PrmRegionScheme, RegionCode)).value(SysQuery::valueEmptyString()); } qbdsExclude = qbdsScheme.addDataSource(tableNum(PrmRegionScheme)); qbdsExclude.joinMode(JoinMode::NoExistsJoin); qbdsExclude.relations(false); qbdsExclude.addLink(fieldNum(PrmRegionScheme, SchemeCode), fieldNum(PRMSchemeTable, SchemeCode)); qbdsExclude.addRange(fieldNum(PrmRegionScheme, RegionCode)) .value(SysQuery::valueNot(userRegionCode) + " && " + SysQuery::valueNot(SysQuery::valueEmptyString())); sysTableLookup = SysTableLookup::newParameters(tableNum(PRMSchemeTable), _ctrl); sysTableLookup.addLookupField(fieldNum(PRMSchemeTable, SchemeCode)); sysTableLookup.addLookupField(fieldNum(PRMSchemeTable, Scheme_Category)); sysTableLookup.addLookupField(fieldNum(PrmRegionScheme, RegionCode)); sysTableLookup.parmQuery(query); sysTableLookup.performFormLookup(); }
How can I modify my approach to ensure that schemes assigned to multiple regions appear in the dropdown correctly while still meeting all the specified criteria? If there is a better way to achieve this functionality, I am open to suggestions.
Thanks,
Ayushaman