Tuesday, 30 January 2018

Resolve Budget dimension through X++ [D365FO]

This one is to resolve budget dimensions. Be careful here to use the right class. Budget plan and Budget register use a different contract class.

   
   public static void getBudgetLedgerDimension()  
   {      
     //use BudgetPlanningContract for Budget plan  
     //use BudgetAccountContract for Budget register  
     BudgetAccountContract budgetAccountContract = new BudgetAccountContract();  
     budgetAccountContract.parmValues(new List(Types::Class));  
     budgetAccountContract.parmAccountStructure('Manufacturing P&L');  
   
     DimensionAttributeValueContract attributeValueContract;  
       
     //Main account      
     attributeValueContract = DimensionAttributeValueContract::construct('MainAccount', '110180');  
     budgetAccountContract.parmValues().addEnd(attributeValueContract);  
          
     //Dimension 1 - repeat this for all other dimensions  
     attributeValueContract = DimensionAttributeValueContract::construct('Department', '022');  
     budgetAccountContract.parmValues().addEnd(attributeValueContract);  
     
     //resolve the dimension  
     BudgetDimensionCombinationServiceProvider budgetDimensionCombinationServiceProvider = BudgetDimensionCombinationServiceProvider::newForBudgetAccountContract(budgetAccountContract);  
     DimensionStorageResult dimensionStorageResult = budgetDimensionCombinationServiceProvider.resolve();  
     if (dimensionStorageResult.parmInvalidValue())  
     {  
       error("Invalid dimension");  
     }  
       
     info(strFmt("Budget Ledger RecId: %1", dimensionStorageResult.parmSavedRecId()));  
   }  

No comments: