Wednesday, July 26, 2023

Code to get individual financial dimensions from default dimension in D365 X++

 

public static void main(Args _args)

   {

       DimensionAttributeValueSetStorage           dimStorage;

 

       dimStorage = DimensionAttributeValueSetStorage::find(68719498720);

       for (int i= 1 ; i<= dimStorage.elements() ; i++)

       {

           if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "BusinessUnit")

           {

               info(strFmt("Business Unit %1",dimStorage.getDisplayValueByIndex(i)));

           }

           if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "CostCenter")

           {

               info(strFmt("cost center %1",dimStorage.getDisplayValueByIndex(i)));

           }

           if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "Department")

           {

               info(strFmt("Department %1",dimStorage.getDisplayValueByIndex(i)));

           }

           if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "ItemGroup")

           {

               info(strFmt("Item Group %1",dimStorage.getDisplayValueByIndex(i)));

           }

           if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "Project")

           {

               info(strFmt("project %1",dimStorage.getDisplayValueByIndex(i)));

           }

       }

   }

................

Other Way :

    public static void main(Args _args)

   {

       DefaultDimensionView defaultDimensinView;

       while select Name, DisplayValue from defaultDimensinView

           where defaultDimensinView.DefaultDimension == 52565465999

       {

           Info (defaultDimensinView.Name +" "+ defaultDimensinView.DisplayValue);

       }

   }

Output :








No comments:

Post a Comment