Skip to main content

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.


Comments

  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

Post a Comment

Popular posts from this blog

How to change client Language in ax 2012

Hello,  As you know that Dynmics Ax run on different languages. So I gonna tell you how to change client language country/region specific. this is nothing but a very simple step to do. Go To > File > Tools > Options > After that go to General tab and select the language which you want to use in your client. then apply and exit. In my case I was using Arabic language. Now restart your client and see the difference. You can do it from your database also . Go to Database server  . In my case it is sql server 2014. Select your database > tables > UserInfo > select the user > change the language code. Done Thanks.

Simple x++ query with enum value range

static void queryEnumValue(Args _args) {     Query                   query;     QueryRun                queryrun;     QueryBuildDataSource    qbds;     QueryBuildRange         qbr;     PurchTable              purchTable;     ;         query = new Query();         qbds = query.addDataSource(tableNum(PurchTable));     qbds.addSortField(fieldNum(PurchTable, PurchId), SortOrder::Ascending);     qbr     = qbds.addRange(fieldNum(PurchTable, PurchStatus));         qbr.value(enum2str(PurchStatus::Received));         queryrun = new QueryRun(query);         while(queryrun.next())     {         purchTable = query...

Unit Conversion by code in ax 2012 R3 , X++

static void unitConversion() {     SysExcelApplication xlsApplication;     SysExcelWorkBooks xlsWorkBookCollection;     SysExcelWorkBook xlsWorkBook;     SysExcelWorksheets xlsWorkSheetCollection;     SysExcelWorksheet xlsWorkSheet;     SysExcelRange xlsRange;     SysExcelCells Cells;     SysExcelCell RCell;     CommaIO inFile;     int nRow,i;     DialogField dialogPath;     Dialog dialog;     Filename filename;         UnitOfMeasureConversion             unitOfMeasureConversion;     UnitOfMeasure                       unitOfMeasure;     EcoResProduct                       ecoResProduct;     RecId               ...