I am using the following code in the Kit Assembly screen which works without errors. This is based on an answer to a question someone asked that Naveen Boga answered some time ago:
try
{
IN.INKitRegisterExt iNKitRegisterExt = PXCache<IN.INKitRegister>.GetExtension<INKitRegisterExt>(row);
decimal? unitCostTotal = Base.Components.Select().FirstTableItems.ToList().Select(x => x.UnitCost).Sum();
int? itemCount = Base.Components.Select().FirstTableItems.ToList().Count;
cache.SetValueExt<INKitRegisterExt.usrAIUnitCostTotal>(row, unitCostTotal);
cache.SetValueExt<INKitRegisterExt.usrAIItemCount>(row, itemCount);
}
catch (Exception error) {
PXTrace.WriteInformation(error);
}
the two custom fields I created are populated correctly. If I try to apply the same logic to the Kit Specifications screen:
try
{
INKitSpecHdrExt iNKitSpecHdrExt = PXCache<INKitSpecHdr>.GetExtension<INKitSpecHdrExt>(row);
decimal? unitCostTotal = Base.StockDet.Select().FirstTableItems.ToList().Select(x => x.UnitCost).Sum();
int? itemCount = Base.StockDet.Select().FirstTableItems.ToList().Count;
cache.SetValueExt<INKitSpecHdrExt.usrAIUnitCostTotal>(row, unitCostTotal);
cache.SetValueExt<INKitSpecHdrExt.usrAIItemCount>(row, itemCount);
}
catch (Exception error) {
PXTrace.WriteInformation(error);
}
I get the error:
\App_RuntimeCode\INKitSpecMaint.cs(31): error CS1061: 'IEnumerable<INKitSpecStkDet>' does not contain a definition for 'ToList' and no accessible extension method 'ToList' accepting a first argument of type 'IEnumerable<INKitSpecStkDet>' could be found (are you missing a using directive or an assembly reference?)
What is the difference between these two screens? How can I get the total row count and sum of UnitCost on the Kit Specifications screen?
Any help would be greatly appreciated,
Phil
Best answer by Fernando Amadoz
View original