如何在 D365FO 的现有量查询中增加字段和数据源(Add the new field or datasource in Inventory On hand form using X++ in D365FO)

我们需要为类 InventDimCtrl_Frm_OnHand 创建一个扩展,以使用方法 modifiedQueryBasedOnDatasourceName 来实现这种Inventory On hand定制。

通过这种方式,我们可以在网格中添加带有过滤选项的新字段。(不使用显示方法)。根据需求,我们可以在表单中添加来自现有数据源以及新数据源的字段。

[ExtensionOf(classStr(InventDimCtrl_Frm_OnHand))]
final class InventDimCtrl_Frm_OnHandClass_Extension
{
    public void modifyQueryBasedOnDatasourceName(
                                                Query _inventSum_DS_Query,
                                                str _inventSum_DS_Name,
                                                FormDataSource _inventDim_DS)
    {
        Query query;
        QueryBuildDataSource qbds;
        QueryBuildDataSource qbdsInventOnHandItemListView;
        QueryBuildDataSource qbdsInventTable;
        Counter loop;
        boolean qbdsExists;
        next modifyQueryBasedOnDatasourceName(_inventSum_DS_Query, _inventSum_DS_Name, _inventDim_DS);
         
        query =   _inventSum_DS_Query;
     
        qbdsInventTable = query.dataSourceTable(tableNum(InventTable));
     
        if (qbdsInventTable)
        {
            qbdsInventTable.addGroupByField(fieldNum(InventTable, BinLocation));
            qbdsInventTable.addGroupByField(fieldNum(InventTable, ItemStatus));
            qbdsInventTable.addGroupByField(fieldNum(InventTable, PackQtyString));
            qbdsInventTable.addGroupByField(fieldNum(InventTable, PartNumber));
            qbdsInventTable.addGroupByField(fieldNum(InventTable, PromotionApplicable));
            qbdsInventTable.addGroupByField(fieldNum(InventTable, PurchaseMultiple));
            qbdsInventTable.addGroupByField(fieldNum(InventTable, ManufacturerCode));
     
            for (loop = 1; loop <= _inventSum_DS_Query.dataSourceCount(); loop++)
            {
                qbds =   _inventSum_DS_Query.dataSourceNo(loop);
     
                if (qbds.table() == tableNum(InventOnHandItemListView))
                {
                    qbdsExists = true;
                    break;
                }
            }
     
            if (!qbdsExists)
            {
                qbdsInventOnHandItemListView = query.dataSourceTable(tableNum(InventTable)).addDataSource(tableNum(InventOnHandItemListView));
                qbdsInventOnHandItemListView.addLink(fieldNum(InventOnHandItemListView, ItemId), fieldNum(InventTable, ItemId));
                qbdsInventOnHandItemListView.joinMode(JoinMode::InnerJoin);
     
                qbdsInventOnHandItemListView.addRange(fieldNum(InventOnHandItemListView, LanguageId)).value(queryValue(new xInfo().language()));
            }
            else
            {
                qbdsInventOnHandItemListView = query.dataSourceTable(tableNum(InventOnHandItemListView));
                    qbdsInventOnHandItemListView.addRange(fieldNum(InventOnHandItemListView, LanguageId)).value(queryValue(new xInfo().language()));
            }
     
            qbdsInventOnHandItemListView.addGroupByField(fieldNum(InventOnHandItemListView, ManufacturerName));
            qbdsInventOnHandItemListView.addGroupByField(fieldNum(InventOnHandItemListView, VendorID));
            qbdsInventOnHandItemListView.addGroupByField(fieldNum(InventOnHandItemListView, VendorName));
            qbdsInventOnHandItemListView.addGroupByField(fieldNum(InventOnHandItemListView, CoverageGroup));
            qbdsInventOnHandItemListView.addGroupByField(fieldNum(InventOnHandItemListView, ProductType));
            qbdsInventOnHandItemListView.addGroupByField(fieldNum(InventOnHandItemListView, ItemName));
            qbdsInventOnHandItemListView.addGroupByField(fieldNum(InventOnHandItemListView, ItemDescription));
            qbdsInventOnHandItemListView.addGroupByField(fieldNum(InventOnHandItemListView, SearchName));
            qbdsInventOnHandItemListView.addGroupByField(fieldNum(InventOnHandItemListView, ProductDimensionGroup));
            qbdsInventOnHandItemListView.addGroupByField(fieldNum(InventOnHandItemListView, StorageDimensionGroup));
            qbdsInventOnHandItemListView.addGroupByField(fieldNum(InventOnHandItemListView, TrackingDimensionGroup));
            qbdsInventOnHandItemListView.addGroupByField(fieldNum(InventOnHandItemListView, ItemModelGroupID));
            qbdsInventOnHandItemListView.addGroupByField(fieldNum(InventOnHandItemListView, BasePurchasePrice));
            qbdsInventOnHandItemListView.addGroupByField(fieldNum(InventOnHandItemListView, BaseSalesPrice));
            qbdsInventOnHandItemListView.addGroupByField(fieldNum(InventOnHandItemListView, BaseCostPrice));
            qbdsInventOnHandItemListView.addGroupByField(fieldNum(InventOnHandItemListView, InventUnit));
            qbdsInventOnHandItemListView.addGroupByField(fieldNum(InventOnHandItemListView, SalesUnit));
            qbdsInventOnHandItemListView.addGroupByField(fieldNum(InventOnHandItemListView, PurchUnit));
            qbdsInventOnHandItemListView.addGroupByField(fieldNum(InventOnHandItemListView, ItemGroupId));
            qbdsInventOnHandItemListView.addGroupByField(fieldNum(InventOnHandItemListView, ProductSubType));
        }
    }
}