- Create shared lookup datasources.
- Add the UI fields to a datasource in createwo page.
- Create lookup dialogs.
- Add the fields to the page UI layout.
- Filter the lookup values using AppCustomizations.js.
commodities is shared by the child datasources commoditygroup and commodity, each of which applies different filters. <maximo-datasource id="commoditiesGroupDS" lookup-data="true" object-structure="MXAPICOMMODITY" offline-immediate-download="true" selection-mode="single">
<schema id="cugp45x">
<attribute id="cu_ej8z1" name="commoditiesid" unique-id="true"/>
<attribute id="cu_d889x" name="commodity" searchable="true"/>
<attribute id="cu_r5v8q" name="description" searchable="true"/>
<attribute id="cu_d3wqg" name="parent"/>
<attribute id="cu_pqny2" name="servicetype"/>
</schema>
<maximo-datasource-override id="commodityGroupDS" pre-load="true" saved-query=""/>
<maximo-datasource-override id="commodityDS"/>
</maximo-datasource>
savedquery or mobile-qbe-filter tag at the datasource level would not support these different filtering requirements in Mobile device, though it works in Role Based Applications in browser. Since we use the same object structure MXAPICOMMODITY, it will display the same values in both lookups in Mobile device. <!-- Separate datasource with savedquery or mobile-qbe-filter DONT work in Mobile -->
<!-- As both datasource use same Object Structure, refresh will work only in RBA appls -->
<maximo-datasource id="commodityGroupDS" lookup-data="true" object-structure="MXAPICOMMODITY" mobile-qbe-filter="{{'parent':'!=*'}}" offline-immediate-download="true" selection-mode="single">
<schema id="cugp45x">
<attribute id="cu_ej8z1" name="commoditiesid" unique-id="true"/>
<attribute id="cu_d889x" name="commodity" searchable="true"/>
<attribute id="cu_r5v8q" name="description" searchable="true"/>
<attribute id="cu_d3wqg" name="parent"/>
<attribute id="cu_pqny2" name="servicetype"/>
</schema>
</maximo-datasource>
<maximo-datasource id="commodityDS" lookup-data="true" object-structure="MXAPICOMMODITY" savedquery="CUSTOMCOMGROUP" offline-immediate-download="true" selection-mode="single">
<schema id="cugp45x">
<attribute id="cu_ej8z1" name="commoditiesid" unique-id="true"/>
<attribute id="cu_d889x" name="commodity" searchable="true"/>
<attribute id="cu_r5v8q" name="description" searchable="true"/>
<attribute id="cu_d3wqg" name="parent"/>
<attribute id="cu_pqny2" name="servicetype"/>
</schema>
</maximo-datasource>
<lookup border="true" datasource="commodityGroupDS" height="400" id="commodityGroupLookup" lookup-attributes="{['commodity', 'description', 'servicetype']}" lookup-heading="Commodity Group" reset-datasource="true" show-search="true" tight="true" width="60">
<lookup border="true" datasource="commodityDS" height="400" id="commodityLookup" lookup-attributes="{['commodity', 'description','parent']}" lookup-heading="Commodity" reset-datasource="false" show-search="true" tight="true" width="60"">
The Commodity Group lookup reloads its datasource whenever it opens with values where parent is null, while the Commodity lookup uses the filtered datasource prepared after a Commodity Group is selected.
<box children-sizes="100" direction="row" fill-child="true" fill-parent-horizontal="true" manage-children="true" padding-bottom=".5" id="cu6znb">
<border-layout fill-parent="true" width="100%" padding="true" id="cuamyd">
<middle horizontal-align="end" horizontal-overflow="hidden" id="cugmw3r">
<smart-input id="cudq45" label="Commodity Group" lookup="commodityGroupLookup" enable-lookup-buttongroup="true" placeholder="Enter Commodity Group" select-lookup-attribute="commodity" value="{dsCreateWo.item.commoditygroup}"/>
<smart-input id="cdrq46" label="Commodity" lookup="commodityLookup" enable-lookup-buttongroup="true" placeholder="Enter Commodity" select-lookup-attribute="commodity" value="{dsCreateWo.item.commodity}"/>
</middle>
</border-layout>
</box>
onAfterLoadData() method to display only top-level commodity groups (records that do not have a parent).// This method will filter the values in Commodity Group field // to display items without parent async onAfterLoadData(dataSource, items) { if (dataSource.name === 'commodityGroupDS') { dataSource.clearQBE(); dataSource.setQBE('parent', '!=', '*'); await dataSource.searchQBE(); } }
onValueChanged() method to filter the Commodity datasource so that only child records belonging to the selected Commodity Group are displayed.
// This method will filter the values in Commodity field
// with a value choosen in Commodity Group field
async onValueChanged({ datasource, item, field, oldValue, newValue }) {
if (field === 'commoditygroup') {
item.commodity = null;
const commodityDS = this.app.findDatasource("commodityDS");
commodityDS.clearQBE();
commodityDS.setQBE("parent", "=", item.commoditygroup);
await commodityDS.searchQBE();
}
}
- The Commodity Group lookup displays only top-level commodity groups.
- Selecting a Commodity Group automatically filters the Commodity lookup.
- Users can only select Commodities that belong to the chosen Commodity Group.
- The same lookup datasource can be reused across multiple pages without duplicating configuration.