ItemId lookup with Category and CategoryHierarchy fields filter

public void lookup(FormControl _formControl, str _filterStr) { SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(InventTable), _formControl); Query query = new Query(); QueryBuildDataSource qbds, qbdsProductCategory, qbdsCategory, qbdsCategoryHierarchy; QueryBuildRange qbrCategory, qbrCategoryHierarchy; ; qbds = query.addDataSource(tableNum(InventTable)); qbds.addGroupByField(fieldNum(InventTable, ItemId)); qbds.addGroupByField(fieldNum(InventTable, NameAlias)); if (WHSInventFixedLocation.Category || WHSInventFixedLocation.CategoryHierarchy) { qbdsProductCategory = qbds.addDataSource(tableNum(EcoResProductCategory)); qbdsProductCategory.addLink(fieldNum(EcoResProductCategory, Product), fieldNum(InventTable, Product)); qbdsProductCategory.joinMode(JoinMode::InnerJoin); qbdsCategory = qbdsProductCategory.addDataSource(tableNum(EcoResCategory)); qbdsCategory.relations(true); if (WHSInventFixedLocation.Category) { qbrCategory = qbdsCategory.addRange(fieldNum(EcoResCategory, RecId)); qbrCategory.value(con2Str(element.getCategoriesList(WHSInventFixedLocation.Category))); } else if (WHSInventFixedLocation.CategoryHierarchy) { qbdsCategoryHierarchy = qbdsCategory.addDataSource(tableNum(EcoResCategoryHierarchy)); qbdsCategoryHierarchy.relations(true); qbrCategoryHierarchy = qbdsCategoryHierarchy.addRange(fieldNum(EcoResCategoryHierarchy, RecId)); qbrCategoryHierarchy.value(SysQuery::value(WHSInventFixedLocation.CategoryHierarchy)); } } sysTableLookup.addLookupField(fieldNum(InventTable, ItemId), true); sysTableLookup.addLookupField(fieldNum(InventTable, NameAlias)); sysTableLookup.parmQuery(query); sysTableLookup.performFormLookup(); } public container getCategoriesList(RefRecId _currentCategory) { EcoResCategory ecoResCategory = EcoResCategory::find(_currentCategory), ecoResCategoryChild; container categoriesList; ; while select RecId from ecoResCategoryChild where ecoResCategoryChild.NestedSetLeft >= ecoResCategory.NestedSetLeft && ecoResCategoryChild.NestedSetRight <= ecoResCategory.NestedSetRight { categoriesList += ecoResCategoryChild.RecId; } return categoriesList; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.