How to convert between units in Dynamics AX 2012 using X++?

 
Qty unitConv(ItemId            _itemId,
                        UnitIDBase    _fromUnit,
                        UnitIDbase     _toUnit,
                        Qty                 _qty)
{
    
    Qty                                                    ret;   
    UnitOfMeasureConverter_Product  unitConverter   = UnitOfMeasureConverter_Product::construct();    
    
    
    unitConverter.parmProduct(InventTable::find(_itemId).Product);
    unitConverter.parmFromUnitOfMeasure(UnitOfMeasure::unitOfMeasureIdBySymbol(_fromUnit));
    unitConverter.parmToUnitOfMeasure(UnitOfMeasure::unitOfMeasureIdBySymbol(_toUnit));
    unitConverter.parmRoundAbsoluteValue(NoYes::No);
    unitConverter.parmApplyRounding(NoYes::No);
    
    ret = unitConverter.convertValue(_qty);
 
    return ret;   
}

Comments

Popular posts from this blog

How to loop through enum in dynamics ax 2012 using x++

How to read from csv file in Dynamics AX 2012 Through X++

How to Create Transfer Journal in Dynamics AX 2012 Through X++