Thursday, November 23, 2017

AX - How get aggregate select value - max(), count()

For aggregate x++ select functions you can use this form:
calcDate = ( select maxof( calcdate ) from ProdParmBomCalc 
where ProdParmBOMCalc.ProdId == source.TransRefId ).calcdate;
Supported aggregate functions: sum, avg, minof , maxof, count.

For count function you can use this code:
int iCount;

iCount =
  ( select count(recId) from prodRoute
    where
    prodRoute.ProdId == source.ProdId &&
    prodRoute.OprPriority == RouteOprPriority::Primary 
  ).recId;
        
if ( iCount != 0 ) {
  bError = true;            
}

No comments:

Post a Comment