1. Assuming you are looking to add the PdsVendBatchId on the InventOnhandItem form. Looks like on changing the display dimensions the InventDim is appearing blank and so is InventbatchId. As Martin rightly said, you need to add a validation like this. IF the batch id is blank your code could break.
else if (!inventDimParmGroupBy.InventBatchIdFlag)
{
//some code
_inventSum_DS_Query.dataSourceTable(tableNum(InventBatch)).relations(false);
_inventSum_DS_Query.dataSourceTable(tableNum(InventBatch)).joinMode(JoinMode::OuterJoin);
_inventSum_DS_Query.dataSourceTable(tableNum(InventBatch)).clearLinks();
_inventSum_DS_Query.dataSourceTable(tableNum(InventBatch)).addLink(fieldNum(InventDim, inventBatchId), fieldNum(InventBatch, inventBatchId));
_inventSum_DS_Query.dataSourceTable(tableNum(InventBatch)).addLink(fieldNum(InventSum, ItemId), fieldNum(InventBatch, itemId), tableStr(InventSum));
_inventSum_DS_Query.dataSourceTable(tableNum(InventBatch)).addGroupByField(fieldNum(InventBatch, PdsVendBatchId));
//Make the vendor batch field available in the query result
_inventSum_DS_Query.addSelectoinField(fieldNum(InventBatch, PdsVendBatchId), SelectionField::QueryValue);
}
2. An alternative to the above suggestion. You can also use the InventOnhandItem and write a COC like this. Tried the below suggestion and it worked (in case if the requirement is to add the PdsVendBatchId to the On Hand screen).
[ExtensionOf(formDataSourceStr(InventOnhandItem, InventSumDeltaDim))]
final class InventSumDeltaDim_InventOnhandItem_DS_Extension
{
public void init()
{
next init();
QueryBuildDataSource qbdsInventSum = this.queryBuildDataSource();
QueryBuildDataSource qbdsInventDim;
QueryBuildDataSource qbdsInventBatch;
// Existing join to InventDim (usually already there)
qbdsInventDim = qbdsInventSum.addDataSource(tableNum(InventDim));
qbdsInventDim.joinMode(JoinMode::ExistsJoin);
qbdsInventDim.addLink(fieldNum(InventSumDeltaDim, InventDimId),
fieldNum(InventDim, InventDimId));
// Join InventBatch via InventDim.InventBatchId
qbdsInventBatch = qbdsInventDim.addDataSource(tableNum(InventBatch));
qbdsInventBatch.joinMode(JoinMode::OuterJoin); // Assumption - Outer because not every item has batch
qbdsInventBatch.relations(true);
qbdsInventBatch.addLink(fieldNum(InventDim, InventBatchId),
fieldNum(InventBatch,InventBatchId));
// Select the vendor batch field so it can be displayed
qbdsInventBatch.addSelectionField(fieldNum(InventBatch, PdsVendBatchId), SelectionField::QueryValue);
}
}
In addition to this, set the Autodeclaration property to Yes for the field after this field is added to the form extension.
[ExtensionOf(formStr(InventOnhandItem))]
final class InventOnhandItem_Form_Extension
{
public void init()
{
next init();
this.design().controlName(formControlStr(InventOnhandItem, InventBatch_PdsVendBatchId)).visible(true);
}
}
Hope this helps. Happy to answer questions, if any.