Wednesday, 15 July 2015

Fetch Financial Dimension and dimension description through code in Ax 2012

I am writing this post to demonstrate to find Fetch Financial Dimension through code in Ax 2012.


// declare buffer

SalesOrderDataTmp                         _salesOrderDataTmp;
DimensionAttributeValueSet           dimAttrValueSet;    
DimensionAttributeValueSetItem   dimAttrValueSetItem;   
 DimensionAttributeValue               dimAttrValue;    
DimensionAttribute                         dimAttr;


// get financial dimension            dimAttrValueSet = DimensionAttributeValueSet::find(salesLine.DefaultDimension);

// Find all of the 'value set items' linked against the 'value set'            
financialDim="";            
while select DimensionAttributeValue from dimAttrValueSetItem                
where   dimAttrValueSetItem.DimensionAttributeValueSet   == dimAttrValueSet.RecId            
{                
dimAttrValue        = DimensionAttributeValue::find(dimAttrValueSetItem.DimensionAttributeValue);
// Find the underlying attribute.                dimAttr             = DimensionAttribute::find(dimAttrValue.DimensionAttribute);
//info(dimAttr.Name + ' - ' + dimAttrValue.getValue());
if (dimAttr.Name == 'R1_LegalEntity')
{
// *******************************
// dimAttrValue.getName() fetches the description of the dimension
god_salesOrderDataTmp.Dimesnions1   = dimAttrValue.getName();
                        
// *******************************
// dimAttrValue.getValue() fetches the description of the dimension
god_salesOrderDataTmp.Dimesnions1   = dimAttrValue.getValue();
}                
if (dimAttr.Name == 'R2_Department')                    
god_salesOrderDataTmp.Dimension2   = dimAttrValue.getName(); // .getValue();                
if (dimAttr.Name == 'R3_Region')                    
god_salesOrderDataTmp.Dimension3   = dimAttrValue.getName();                
if (dimAttr.Name == 'R4_CostCenter')                    
god_salesOrderDataTmp.Dimension4   = dimAttrValue.getName();               
 if (dimAttr.Name == 'R5_ProductCatagories')                    
god_salesOrderDataTmp.Dimension5   = dimAttrValue.getName();                
if (dimAttr.Name == 'R6_SalesType')                    
god_salesOrderDataTmp.Dimension6   = dimAttrValue.getName();

financialDim += dimAttrValue.getName() +",";            

}
god_salesOrderDataTmp.insert();


No comments:

Post a Comment

Import General journal from excel in D365 F&O

 Hi Guys, Import General journal from excel in D365 F&O Code:  using System.IO; using OfficeOpenXml; using OfficeOpenXml.ExcelPackage; u...