Below example demonstrates to find the Item On hand available. Used X++ query class and built dynamically, you can add add/remove the invent dimensions as needed.
static void findonHand(Args _args)
{
InventSum inventSum;
InventDim inventDim;
InventTable inventTable;
Query query;
QueryBuildDataSource qbs;
QueryBuildRange qbr;
QueryRun qr;
;
query = new Query();
qbs = query.addDataSource(tablenum(InventSum));
qbs.addRange(fieldNum(InventSum, ItemId)).value("YourItemId");
qbs.addRange(fieldNum(InventSum, Closed)).value(QueryValue(NoYes::No));
InventSum::queryAddSumFields(query.dataSourceTable(tablenum(InventSum)));
qbs = qbs.addDataSource(tablenum(InventDim));
qbs.orderMode(OrderMode::GroupBy);
//You can add add/remove inventory dimensions
qbs.addGroupByField(fieldNum(InventDim, InventSiteId));
qbs.addGroupByField(fieldNum(InventDim, InventLocationId));
qbs.addGroupByField(fieldNum(InventDim, inventBatchId));
qbs.addGroupByField(fieldNum(InventDim, wMSLocationId));
qbs.relations(false);
qbs.addLink(
fieldnum(InventSum, InventDimId),
fieldNum(InventDim, InventDimId));
//info (query.dataSourceTable(tablenum(InventSum)).toString());
qr = new Queryrun(query);
while(qr.next())
{
inventSum = qr.get(tableNum(InventSum));
inventDim = qr.get(tableNum(inventDim));
if (inventSum.AvailPhysical > 0)
info (Strfmt("%1 - %2 - %3 - %4 - %5", inventSum.AvailPhysical, inventDim.InventSiteId,
inventDim.InventLocationId, inventDim.inventBatchId, inventDim.wMSLocationId));
}
}
Happy DAXing...
static void findonHand(Args _args)
{
InventSum inventSum;
InventDim inventDim;
InventTable inventTable;
Query query;
QueryBuildDataSource qbs;
QueryBuildRange qbr;
QueryRun qr;
;
query = new Query();
qbs = query.addDataSource(tablenum(InventSum));
qbs.addRange(fieldNum(InventSum, ItemId)).value("YourItemId");
qbs.addRange(fieldNum(InventSum, Closed)).value(QueryValue(NoYes::No));
InventSum::queryAddSumFields(query.dataSourceTable(tablenum(InventSum)));
qbs = qbs.addDataSource(tablenum(InventDim));
qbs.orderMode(OrderMode::GroupBy);
//You can add add/remove inventory dimensions
qbs.addGroupByField(fieldNum(InventDim, InventSiteId));
qbs.addGroupByField(fieldNum(InventDim, InventLocationId));
qbs.addGroupByField(fieldNum(InventDim, inventBatchId));
qbs.addGroupByField(fieldNum(InventDim, wMSLocationId));
qbs.relations(false);
qbs.addLink(
fieldnum(InventSum, InventDimId),
fieldNum(InventDim, InventDimId));
//info (query.dataSourceTable(tablenum(InventSum)).toString());
qr = new Queryrun(query);
while(qr.next())
{
inventSum = qr.get(tableNum(InventSum));
inventDim = qr.get(tableNum(inventDim));
if (inventSum.AvailPhysical > 0)
info (Strfmt("%1 - %2 - %3 - %4 - %5", inventSum.AvailPhysical, inventDim.InventSiteId,
inventDim.InventLocationId, inventDim.inventBatchId, inventDim.wMSLocationId));
}
}
Happy DAXing...
No comments:
Post a Comment