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;
}
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
Post a Comment