Monthly Archives: May 2016

[AX 2012 R3] How to get avail quantity of a product by ItemId and get details by inventory dimensions (InventDimId)

 InventDimOnHand onHand;
 InventDimOnHandIterator iter;
 InventDimOnHandMember member;
 InventOnhand inventOnhand;
 ItemId itemId;
 InventDim inventDimCrit;
 InventDimParm inventDimParmCrit, inventDimParmOnHandLevel;
 InventDim inventDim;
 InventDimOnHandLevel level;
 ;

 itemId = '123456';

 // Known dimensions
 inventDimCrit.wMSLocationId = 'location01';
 inventDimCrit = InventDim::findOrCreate(inventDimCrit);

 // Determine which of the known dimensions to use
 inventDimParmCrit.WMSLocationIdFlag = true;

 level = InventDimOnHandLevel::DimParm;

 // Determines the level of detail returned
 inventDimParmOnHandLevel.ItemIdFlag = true;
 inventDimParmOnHandLevel.InventLocationIdFlag = true;
 inventDimParmOnHandLevel.WMSLocationIdFlag = true;
 inventDimParmOnHandLevel.InventBatchIdFlag = true;

 onHand = InventDimOnHand::newPhysicalArrived(itemId, inventDimCrit, InventDimParmCrit, level, inventDimParmOnHandLevel);

 iter = onHand.onHandIterator();
 while (iter.more())
 {
 member = iter.value();
 inventDim = InventDim::find(member.parmInventDimId());
 inventDimParmOnHand.initFromInventDim(inventDim);
 inventOnHand = InventOnhand::newParameters(itemId, inventDim,inventDimParmOnHand);
 info(con2str([member.parmItemId(), inventDim.inventLocationId, inventDim.inventBatchId, inventDim.LicensePlateId, inventDim.inventSerialId, member.parmInventQty(), inventOnHand.availPhysical()]));

 iter.next();
 }

 info('Done'); 

[AX 2012 R3] How to get product color description

We want to display the description of a dimension (in this case the colour) of a product

We just need the ItemId and InventColorId

productAx

static void GetColorDescription(Args _args)
{
 ItemId ItemId = "123456789"; //Change with your ItemId
 EcoResProductMasterColor EcoResProductMasterColor;
 EcoResProductMasterDimensionValue EcoResProductMasterDimensionValue;
 EcoResColor EcoResColor;
 EcoResProductMaster EcoResProductMaster;
 EcoResProductMasterDimValueTranslation EcoResProductMasterDimValueTranslation;
 
 EcoResColorName EcoResColorName = InventDim::find("InventDimId").InventColorId; 

 select * from EcoResProductMasterDimValueTranslation
 join RecId from EcoResProductMasterDimensionValue
 where EcoResProductMasterDimValueTranslation.ProductMasterDimensionValue
 == EcoResProductMasterDimensionValue.RecId
 join RecId from EcoResProductMasterColor
 where EcoResProductMasterDimensionValue.RecId == EcoResProductMasterColor.RecId
 join RecId from EcoResColor
 where EcoResColor.RecId == EcoResProductMasterColor.Color
 && EcoResColor.Name == EcoResColorName
 join RecId from EcoResProductMaster
 where EcoResProductMasterColor.ColorProductMaster == EcoResProductMaster.RecId
 && EcoResProductMaster.DisplayProductNumber == ItemId;

 info(EcoResProductMasterDimValueTranslation.Name);
}

In case you don’t have any translaction
ax2012r3_product_with_no_translation
the object EcoResProductMasterDimValueTranslation.Name will be empty, so you can retrive the Deault value using this code:

static void GetColorDescription(Args _args)
{
 ItemId ItemId = "123456789"; //Change with your ItemId
 EcoResProductMasterColor EcoResProductMasterColor;
 EcoResProductMasterDimensionValue EcoResProductMasterDimensionValue;
 EcoResColor EcoResColor;
 EcoResProductMaster EcoResProductMaster;
 EcoResProductMasterDimValueTranslation EcoResProductMasterDimValueTranslation;
 
 EcoResColorName EcoResColorName = InventDim::find("InventDimId").InventColorId; 

 select * from EcoResProductMasterDimValueTranslation
 join RecId from EcoResProductMasterDimensionValue
 where EcoResProductMasterDimValueTranslation.ProductMasterDimensionValue
 == EcoResProductMasterDimensionValue.RecId
 join RecId from EcoResProductMasterColor
 where EcoResProductMasterDimensionValue.RecId == EcoResProductMasterColor.RecId
 join RecId from EcoResColor
 where EcoResColor.RecId == EcoResProductMasterColor.Color
 && EcoResColor.Name == EcoResColorName
 join RecId from EcoResProductMaster
 where EcoResProductMasterColor.ColorProductMaster == EcoResProductMaster.RecId
 && EcoResProductMaster.DisplayProductNumber == ItemId;

if(EcoResProductMasterDimValueTranslation.Name)
{
info(EcoResProductMasterDimValueTranslation.Name);
}
else
{
EcoResProductMasterDimValueTranslation = EcoResProductMasterDimValueTranslation::getNameOrDefaultName(EcoResProductMasterDimensionValueId, SystemParameters::getSystemLanguageId()); info(EcoResProductMasterDimValueTranslation.Name);
info(EcoResProductMasterDimValueTranslation.Name);
}