Dear All, I'm working on a display method in AX 2009, which queries the ReqTrans table to sum its Qty field to acquire totals for planned production orders.
I can easily do a Select ItemId, Sum(Qty) from reqTrans where reqTrans.ItemId == InventSum.ItemId.
However, on my form's grid control Dimensions are also displayed and whereas Warehouse '001' the main warehouse displays the correct totaled amount, so also will the row showing warehouse '999' the quarantined warehouse. And that warehouse should only show a null value for the Qty field instead of a duplicate value.
I used InventDim's findDim method to pass the correct DIMs to my select statement to return only warehouse '001'. This works but I still have 2-difficulties.
- It only returns the first record, whereas there are multiples having the same InventDim.InventDimId and matching reqTrans.CovInventDimId, as well as matching InventSum.ItemId and reqTrans.ItemId.
- I need a way to total the value of the Qty field.
My code is as follows:
Display ReqQty PlannedProdOrders(InventSum _inventSum)
{
InventDim dim;
ReqTrans reqTrans;
real qtyProdOrder = 0.00;
;
dim.configId = this.inventDim().configId;
dim.InventSizeId = this.inventDim().InventSizeId;
dim.InventColorId = this.inventDim().InventColorId;
dim.InventSiteId = this.inventDim().InventSiteId;
dim.InventLocationId = this.inventDim().InventLocationId;
dim.inventBatchId = this.inventDim().inventBatchId;
dim.wMSLocationId = this.inventDim().wMSLocationId;
dim.wMSPalletId = this.inventDim().wMSPalletId;
dim.inventSerialId = this.inventDim().inventSerialId;
dim = InventDim::findDim(dim,false); //Use 'findDim' to pass correct dim to select.
select ItemId, CovInventDimId, ReqPlanId, RefType, Qty from reqTrans
where reqTrans.ItemId == _inventSum.ItemId && reqTrans.CovInventDimId == dim.inventDimId
&& reqTrans.ReqPlanId == 'Static' && reqTrans.RefType == ReqRefType::BOMLine
&& inventDim.configId == dim.configId
&& inventDim.InventSizeId == dim.InventSizeId
&& inventDim.InventColorId == dim.InventColorId
&& inventDim.InventSiteId == dim.InventSiteId
&& inventDim.InventLocationId == dim.InventLocationId
&& inventDim.inventBatchId == dim.inventBatchId
&& inventDim.wMSLocationId == dim.wMSLocationId
&& inventDim.wMSPalletId == dim.wMSPalletId
&& inventDim.inventSerialId == dim.inventSerialId;
qtyProdOrder = reqTrans.Qty;
return qtyProdOrder;
}
I need assistance with the following 2-things please.
- Loop through all matching records, not just the first one.
- Total each value from the Qty field.
I started to use a While Select statement but then the compiler complained about a syntax error.
Thank you in advance for your help.