Vasanth Arivali's Blog

Posts Tagged ‘how to get dimension values in Ax 2012

Hi Guys,

Here I have posted a sample job to fetch the Dimension values based on the LedgerDimension in Ax 2012. This will give the clear picture how the LedgerDimenion(Combination of MainAccount-Dim1-Dim2-Dim3) is mapped with each Dimension Values

/// This will get the Dimension based on your AccountStructure of the Current Company and Posting Profile Setup.

static void getDimensionValueFromLedgerDimension(Args _args)

{

DimensionAttribute                          dimensionAttributeTable;

DimensionAttributeValueGroupStatus          dimAttrValueGroupStatusTable;

DimensionAttributeValueGroupCombination     dimAttrValueGroupComboTable;

DimensionAttributeValueGroup                dimAttrValueGroupTable;

DimensionAttributeLevelValue                dimAttrLevelValueTable;

DimensionAttributeValue                     dimAttrValueTable;

DimensionAttrValueCOAOverride               dimAttrValueCOAOverrideTable;

DimensionAttrValueLedgerOverride            dimAttrValueLedgerOverrideTable;

DimensionFinancialTag                       dimensionFinancialTagTable;

InventPosting                               inventPostingTable;

DimensionValue                              Dimension1, Dimension2, Dimension3;

MainAccountNum                              LedgerAccount;

RecId                                       LedgerRecId, dimCombinationId;

dimCombinationId    = 5637144728; // for example here i gave a valid ledgerdimension

// find MainAccountId from LedgerDimension

LedgerAccount       = MainAccount::findByLedgerDimension(dimCombinationId).MainAccountId;

LedgerRecId         = Ledger::findLedgerRecIdByLegalEntity(CompanyInfo::findDataArea(curext()).RecId);

Dimension1 = “”;

Dimension2 = “”;

Dimension3 = “”;

while select Ordinal from dimAttrValueGroupComboTable order by Ordinal

where dimAttrValueGroupComboTable.DimensionAttributeValueCombination == dimCombinationId

join dimAttrValueGroupTable

where dimAttrValueGroupTable.RecId == dimAttrValueGroupComboTable.DimensionAttributeValueGroup

outer join dimAttrValueGroupStatusTable

where dimAttrValueGroupStatusTable.DimensionAttributeValueGroup == dimAttrValueGroupTable.RecId

join dimAttrLevelValueTable

where dimAttrLevelValueTable.DimensionAttributeValueGroup == dimAttrValueGroupTable.RecId

join pessimisticLock IsSuspended, IsTotal, ActiveFrom, ActiveTo, DimensionAttribute, RecId, EntityInstance from dimAttrValueTable

where dimAttrValueTable.RecId == dimAttrLevelValueTable.DimensionAttributeValue

outer join pessimisticLock IsSuspended, ActiveFrom, ActiveTo, RecId from dimAttrValueCOAOverrideTable

where dimAttrValueCOAOverrideTable.DimensionAttributeValue == dimAttrValueTable.RecId && dimAttrValueCOAOverrideTable.ChartOfAccounts == LedgerChartOfAccounts::current()

outer join pessimisticLock IsSuspended, ActiveFrom, ActiveTo, RecId from dimAttrValueLedgerOverrideTable

where dimAttrValueLedgerOverrideTable.DimensionAttributeValue == dimAttrValueTable.RecId && dimAttrValueLedgerOverrideTable.Ledger == LedgerRecId

{

dimensionFinancialTagTable = null;

select * from dimensionFinancialTagTable

where dimensionFinancialTagTable.RecId == dimAttrValueTable.EntityInstance

join dimensionAttributeTable

where dimensionAttributeTable.RecId == dimAttrValueTable.DimensionAttribute;

if (dimensionAttributeTable.Name == ‘Department’)

{

Dimension1 = dimensionFinancialTagTable.Value;

}

if (dimensionAttributeTable.Name == ‘CostCenter’)

{

Dimension2 = dimensionFinancialTagTable.Value;

}

if (dimensionAttributeTable.Name == ‘Purpose’)

{

Dimension3 = dimensionFinancialTagTable.Value;

}

}

info(strFmt(“%1     %2      %3”,Dimension1,Dimension2,Dimension3));

}


Welcome

What’s happening?

Categories

Join 13 other followers