Tuesday, 30 January 2018

Resolve default dimension through X++ [D365FO]

This one is resolving the Default dimension

   
   public static void getDefaultDimension()  
   {  
     DimensionNameValueListContract dimensionNameValueListContract = new DimensionNameValueListContract();  
     dimensionNameValueListContract.parmValues(new List(Types::Class));  
       
     DimensionAttributeValueContract dimensionAttributeValueContract;  
   
     //Dimension 1 - repeat this for all other dimensions  
     dimensionAttributeValueContract = DimensionAttributeValueContract::construct('Department', '022');  
     dimensionNameValueListContract.parmValues().addEnd(dimensionAttributeValueContract);  
       
     //resolve the dimension  
     DimensionNameValueListServiceProvider dimensionNameValueListServiceProvider = DimensionNameValueListServiceProvider::newForDimensionNameValueListContract(dimensionNameValueListContract);  
     DimensionStorageResult dimensionStorageResult = dimensionNameValueListServiceProvider.resolve();  
       
     if (dimensionStorageResult.parmInvalidValue())  
     {  
       error("Invalid dimension");  
     }  
   
     info(strFmt("Default dimension RecId: %1", dimensionStorageResult.parmSavedRecId()));  
   }  

No comments: