Monday, September 11, 2017

Find product attributes and values for an item in AX 2012 via X++

In the event you need to see what the product attributes are while debugging some stuff, run the below script.

This is for AX 2012 but probably works for D365, I'm not sure. Give it a shot.

It literally takes an item id and gives you the attributes and values in those attributes. Pretty straight forward

static void DAXGetProductAttributes(Args _args)
{
    EcoResProductAttributeValue ecoResProductAttributeValue;
    EcoResAttribute             ecoResAttribute;
    EcoResValue                 ecoResValue;
    ItemId                      itemId      = 'A10021'; // This is a sample Item Id
    InventTable                 inventTable = InventTable::find(itemId);

    while select RecId from ecoResProductAttributeValue
         where ecoResProductAttributeValue.Product   == inventTable.Product
         join Name from ecoResAttribute
             where ecoResAttribute.RecId                 == ecoResProductAttributeValue.Attribute
             join ecoResValue
               where ecoResValue.RecId                     == ecoResProductAttributeValue.Value
    {
        info(strFmt("%1 - %2 - %3", InventTable.ItemId, ecoResAttribute.Name, ecoResValue.value()));
    }
}