Vasanth Arivali's Blog

Archive for December 2011

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));

}

Hi,

Here I have written a sample code to execute a simple secenario with “Common” Table in Ax 2012

static void Job_UsingCommonTable(Args _args)

{

#define.ledgerDimension(‘LedgerDimension’)

#define.inventPosting(‘InventPosting’)

#define.inventItemGroupForm(‘InventItemGroupForm’)

InventPosting                    inventPosting;

container                           conCompanies = [‘CEE’, ‘CUE’, ‘DMO’];

InventItemGroupForm    inventItemGroupForm;

container                           tableList = [tableStr(Inventposting), tableStr(InventItemGroupForm)];

TableName                        name;

int                                       loop;

void updateDimension(Common common)

{

DimensionAttributeValueCombination  dimensionAttributeValueCombination;

ttsbegin;

while select crossCompany:conCompanies common

{

select forUpdate LedgerDimensionType, RecId from dimensionAttributeValueCombination

where

dimensionAttributeValueCombination.RecId == common.(fieldName2id(common.TableId,  #ledgerDimension));

if(dimensionAttributeValueCombination.RecId)

{

dimensionAttributeValueCombination.LedgerDimensionType =  LedgerDimensionType::Account;

dimensionAttributeValueCombination.doUpdate();

}

}

ttsCommit;

info(strFmt(‘DimensionAttributeValueCombination is update for Table: %1’, tableId2name(common.TableId)));

}

for (loop = 1; loop <= conLen(tableList); loop++)

{

name = conPeek(tableList, loop);

switch(name)

{

case #inventPosting :

updateDimension(inventPosting);

break;

case #inventItemGroupForm :

updateDimension(inventItemGroupForm);

break;

}

}

info(‘Completed’);

}

Thanks & Regards,

Vasanth Arivali


Welcome

What’s happening?

Error: Twitter did not respond. Please wait a few minutes and refresh this page.

Categories

Join 13 other followers