How to get Item financial dimension with category hierarchies in Ax 2012

Description:-

In this post we will look into how to get item financial dimension and category hierarchy using x++.

static void dev_Export_ItemData(Args _args)
{
    Set                                     set = new Set(Types::String);
    CommaIo                           myFile;
    container                         myCon;
    FileIoPermission                     perm;
    InventTable                       InventTable,InventTable1;
    DimensionAttributeValueSet              DimensionAttributeValueSet;
    DimensionAttributeValueSetItem          DimensionAttributeValueSetItem;
    DimensionAttributeValue               DimensionAttributeValue;
    DimensionAttribute                   DimensionAttribute;
    EcoResProductCategory                EcoResProductCategory;
    EcoResCategory                       EcoResCategory,EcoResCategoryNext;
    EcoResCategoryId                     parentCategory;
    EcoResProduct                        EcoResProduct;
    List                              li;
    ListEnumerator                       enumer;
    #File
    #Properties
    #AOT
    ;
    InventTable1.clear();
    while select * from InventTable1
    where InventTable1.ItemId == "Item number"
    {
      info(InventTable1.ItemId);
      info("----Financial Dimension----");
      //Financial Dimension start
      InventTable.clear();
      DimensionAttributeValueSet.clear();
      DimensionAttributeValueSetItem.clear();
      DimensionAttributeValue.clear();
      DimensionAttribute.clear();
      while select * from InventTable
        where InventTable.ItemId == InventTable1.ItemId
      join RecId from DimensionAttributeValueSet
        where  DimensionAttributeValueSet.RecId == InventTable.DefaultDimension
      join RecId, DisplayValue from DimensionAttributeValueSetItem
        where DimensionAttributeValueSetItem.DimensionAttributeValueSet == DimensionAttributeValueSet.RecId
      join RecId from DimensionAttributeValue
        where DimensionAttributeValue.RecId == DimensionAttributeValueSetItem.DimensionAttributeValue
      join RecId, Name from DimensionAttribute
        where DimensionAttribute.RecId == DimensionAttributeValue.DimensionAttribute
      {
            info(DimensionAttribute.Name+"----"+DimensionAttributeValueSetItem.DisplayValue);
      }
        //Financial dimension end
        info("----Category Hierarchies----");
        //Category start
        EcoResCategory.clear();
        EcoResProductCategory.clear();
        li = new List(Types::String);
        li.empty();

        select * from EcoResCategory
        join RecId from EcoResProductCategory
        where EcoResCategory.RecId == EcoResProductCategory.Category
        && EcoResProductCategory.Product == EcoResProduct::findByDisplayProductNumber(InventTable1.ItemId).RecId;
        parentCategory = EcoResCategory.ParentCategory;
        while (parentCategory)
        {
            li.addStart(EcoResCategory.Name);
            select * from EcoResCategory
                where EcoResCategory.RecId ==  parentCategory
                && EcoResCategory.ParentCategory != 0;
            if(EcoResCategory.RecId == 0)
            {
                EcoResCategoryNext.clear();
                select * from EcoResCategoryNext
                where EcoResCategoryNext.RecId ==  parentCategory
                && EcoResCategoryNext.ParentCategory == 0;
                li.addStart(EcoResCategoryNext.Name);
            }
            parentCategory = EcoResCategory.ParentCategory;
        }
        enumer = li.getEnumerator();
        enumer.reset();
        while (enumer.moveNext())
        {
            info(enumer.current());
        }
    }
}

Related Posts

Previous
Next Post »

Thanks for comments.....