1

I m working with dynamics ax 2012 and i m looking for a fonction that verifie if a product is exist in the procurement category hierarchy This listepage Product Information Management -> Common -> Products -> Released Product show list of product released in the actionpane product ,we have button validate ; when i select a record in the grid control and clicked in the button validate

i should verifie if the procurement category is attached to this product , there is no error ;if no procurement category is attached to this product ,it must display an arror message

Apparently , the procurement category is a category hierarchy which I will go look for if the product is attached for this category, How can i create a fonction to search in the category hierarchy

Can anyone help me?

Alex Kwitny
  • 11,211
  • 2
  • 49
  • 71
Ahmed
  • 259
  • 2
  • 9
  • 26

2 Answers2

2

You need two tables to do that validation:

  1. Table EcoResProductCategory tells who what categories and category hierarchies a product has.
  2. Table EcoResCategoryHierarchyRole tells you what role a category hierarchy has. The role itself is the enum EcoResCategorynamedHierarchyRole and there you can find the element Procurement.

Now you can combine these two tables in a query that checks if the product has a category in a category hierarchy that has the Procurement role.

FH-Inway
  • 4,432
  • 1
  • 20
  • 37
0

In the class EcoResProductValidatonService this class is called by the button validate in th This listepage Product Information Management -> Common -> Products -> Released Product : I m traying this code , what do you think ? is there another why to do that?

EcoResProductCategory               resProductCateg;
         if (TableParm::find().ProcRescatgProduct){

                InventTable = InventTable::find( 'Item id' ); // pass the item id
                resProductCateg = EcoResProductCategory::findByProductIdCategoryHierarchyRole(inventTable.Product,EcoResCategoryNamedHierarchyRole::Procurement);
                if(resProductCateg){
                   info(strFmt(" %1   procurement category is attached to this product ",InventTable.ItemId));

                }else{
                     info(strFmt(" %1 No procurement category is attached to this product ",InventTable.ItemId));
                  }
            }

The problem is the value of resProductCateg is alywas 0 knowing that i have the product in procurment category

Ahmed
  • 259
  • 2
  • 9
  • 26