Thursday, 3 November 2016

Deleting unused Main Account Values in Ax 2012

A financial dimension value is based on the Main Account  record and has been used on a transaction, You cannot delete the Main Account record. 
In order to get rid off un-used dimension values, delete the related records in the following tables1.DimensionAttributeValueCombination
By default the ledger dimension values are stored in DimensionAttributeValueCombination.
The DimensionAttributeValueCombination table contains information about accounts and various dimensions combinations that are used. Anything that uses dimensions will hold reference to a record on this table.
 
2.DimensionAttributeLevelValue
This table contains the usage of  a dimension attribute value in a given dimension hierarchy.
3.DimensionAttributeValueGroup
This table represents a group of values for the specific dimension set.
4.DimensionAttributeValueGroupCombination
It contains the usage of dimension code groups in a  dimension code combination.
It allows a group to be re-used in multiple combination.
5.DimensionAttributeValue
This table contains the values, such as dimension codes, for a specific dimension.

After removing the reference records in the above tables, you can remove main account from its master itself.


Or you can use below code to delete the transaction record.

static void clear_LedgerAttributeCombinations(Args _args)



{

MainAccount mainAccount;

DimensionAttributeValueCombination dimAttributeValueCombo;

DimensionAttributeValueGroupCombination dimAttributeValueGroupCombo;

DimensionAttributeLevelValue dimAttributeLevelValue;

DimensionAttributeValue dimAttributeValue;

;

ttsBegin;

while select mainAccount

where mainAccount.LedgerChartOfAccounts == 5637144576 // Rec id for your COA.you can find it in Main account Table.



{

while select forUpdate dimAttributeLevelValue

where dimAttributeLevelValue.DisplayValue == mainAccount.MainAccountId



{

delete_from dimAttributeValue

where dimAttributeValue.RecId == dimAttributeLevelValue.DimensionAttributeValue &&



dimAttributeValue.EntityInstance == mainAccount.RecId &&

dimAttributeValue.DimensionAttribute == DimensionAttribute::getMainAccountDimensionAttribute();

dimAttributeLevelValue.delete();

while select forUpdate dimAttributeValueGroupCombo

where dimAttributeValueGroupCombo.DimensionAttributeValueGroup == dimAttributeLevelValue.DimensionAttributeValueGroup



{

delete_from dimAttributeValueCombo

where dimAttributeValueCombo.RecId == dimAttributeValueGroupCombo.DimensionAttributeValueCombination;



dimAttributeValueGroupCombo.delete();

}

}

info(strFmt("%1", mainAccount.MainAccountId));



}

ttsCommit;




}

Now you will be able to delete the main accounts.


1 comment:

  1. The post is absolutely fantastic! Lots of great information and inspiration both of which we all need! Also like to admire the time and effort you put into your blog. For more info visit.Microsoft Dynamics AX consultants

    ReplyDelete