Blog

Name is Anant Dubey and the intent to create this blog is to discuss the problems and issues that developer face in the dynamics AX development and to share the new things that come up with the new version of AX.

Monday, September 5, 2022

Get on hand inventory in d365fo

 [ExtensionOf(tableStr(ReqPO))]

final class ReqPOTable_Extension

{

    public void insert(ReqPlanData _reqPlanData)

    {

        InventOnhand    inventOnHand, inventOnHandRWH;

        InventDim       inventDim;

        InventDimParm   inventDimParm;

        

        inventDim = InventDim::find(this.CovInventDimId);

        inventDimParm.initFromInventDim(inventDim);

        inventOnHand = InventOnhand::newParameters(this.ItemId, inventDim, inventDimParm);

        this.GKAvailPhysical = inventOnHand.availPhysical();


        inventOnHandRWH = InventOnhand::newItemId(this.ItemId);

        inventOnHandRWH.parmInventLocationId("TEST");


        this.GKAvailPhysicalRWH = inventOnHandRWH.availPhysical();

        //-------------------------------------------------------------------------------

        this.GKModelGroupId = InventModelGroupItem::findByItemIdLegalEntity(this.ItemId).ModelGroupId;

        //-------------------------------------------------------------------------------

        

        //-------------------------------------------------------------------------------


        EcoResProductCategory   EcoResProductCategory;

        EcoResCategory               EcoResCategory,EcoResCategoryNext;

        EcoResCategoryId            parentCategory;

        List                                    li = new List(Types::String);

        ListEnumerator                 enumer;


        select * from EcoResCategory

        join RecId from EcoResProductCategory

            where EcoResCategory.RecId == EcoResProductCategory.Category

            && EcoResProductCategory.Product == InventTable::find(this.itemId).Product;


        parentCategory = EcoResCategory.ParentCategory;


        while (parentCategory)

        {

            li.addStart(EcoResCategory.Name);


            select * from EcoResCategory

            where EcoResCategory.RecId ==  parentCategory

            && EcoResCategory.ParentCategory != 0;  // skip the top node


            parentCategory = EcoResCategory.ParentCategory;

        }


        enumer = li.getEnumerator();

        while (enumer.moveNext())

        {

            this.GKProductcategory = enumer.current();

        }


        next insert();

    }


}