Populate Grid in X++

If you to populate the grid through code, You must create a temp table in the project.

1- For creating the temp table, filter any temp table in AOT like BOMCalcTransTmp Table.

2- Duplicate the BOMCalcTransTmp table in the project and change the name of the table and the fields of the table as you like.

3- Now add the temp table BOMCalcTransTmp in the Datasource field of the grid.

4- Now the main part is how to populate the grid. You can populate the grid on the init() method or on the button clicked method as shown in the code below;

5- Kindly make the temp table BOMCalcTransTmp table-type InMemory.

BOMCalcTransTmp bomCalcTransTmp;

                while Select bOMCalcTrans where bOMCalcTrans.CalcType == ItemCalcType::Process

                {

                    bomCalcTransTmp.clear();


                    bomCalcTransTmp.CalcType = bOMCalcTrans.CalcType;

                    bomCalcTransTmp.CostGroupId = bOMCalcTrans.CostGroupId;

                    bomCalcTransTmp.Resource = bOMCalcTrans.Resource;

                    bomCalcTransTmp.UnitIdBOMCalcTrans = bOMCalcTrans.UnitId;

                    bomCalcTransTmp.Level = bOMCalcTrans.Level;

                    bomCalcTransTmp.Oprid = bOMCalcTrans.Oprid;

                    bomCalcTransTmp.ConsumptionSum = bOMCalcTrans.consumptionSum();

                    bomCalcTransTmp.CostPricePcsBOMCalcTrans = bOMCalcTrans.costPricePcs();

                    bomCalcTransTmp.CostPriceSumBOMCalcTrans = bOMCalcTrans.costPriceSum();

                    bomCalcTransTmp.DisplayDescription = bOMCalcTrans.displayDescription();

                    bomCalcTransTmp.SalesPricePcsBOMCalcTrans = bOMCalcTrans.salesPricePcs();

                    bomCalcTransTmp.SalesPriceSumBOMCalcTrans = bOMCalcTrans.salesPriceSum();

                  bomCalcTransTmp.insert();

                    }

             SLDBOMCalcTransTmp.setTmpData(bomCalcTransTmp);

        this.formRun().design().controlName("CostGroupDetailGrid").dataSourceObject().executeQuery();

        

5- When the grid is open, then it populates with the fields.


Happy Coding.

Feel free to comment and share.

Comments

Popular posts from this blog

Create custom workflow in D365 X++

Convert amount from one currency to another currency using X++

How to Create Extended Data Types (EDTs) in Finance and Operations of Dynamics 365 -- F&O Customization Part 2