Wednesday, February 9, 2011

Merge two records from one table in AX 2009

In AX 2009, you can merge two records by using the merge() function in a table. For Example if you have posted a project with different department dimensions and now if you would like to merge two records of department dimension then this merge function can be helpful. The sample code is here as follows:

Dimensions dimensions1, dimensions2;
dimensions1 = Dimensions::find(Sysdimension::Department, 'abc');
dimensions2 = Dimensions::find(Sysdimension::Department, 'def');
dimensions1.merge(dimensions2); // Merge Department dimension 'abc' into 'def' department dimension

Now all the transactions which has abc Department dimension will be changed to def in all the tables and Department Dimension 'abc' will be deleted from the dimension table.

So, Folks...............Now its pretty easy to merge two records............


Jonny Wilson said...

I think this is just what we are looking for but we are getting the following error. We want to Merge two existing Company Divisions (Our first Dimensions).... any ideas?

Cannot delete a record in Dimensions (Dimensions).
The operation cannot be completed, since the record was not selected for update. Remember TTSBEGIN/TTSCOMMIT as well as the FORUPDATE clause.

(S)\Data Dictionary\Tables\Dimensions\Methods\Delete - line 80
(C)\Classes\FormButtonControl\Clicked - line 13

Giridhar Raj said...

If the above post is your requirement then it will definitely work. Please copy and paste the above code and then change the values in it....