Copy data between companies

I have recently done some modifications that required certain data that was very time demanding to enter manually in Dynamics Ax. This data was also needed in a number of different companies which meant that I had to enter this data several times.

Because I’m against all that is time consuming I created a script that only require that I enter my data once and then lets me copy this data to the other companies.

This script is the result of different previous blog entries that already exists in this site:

Basics of changecompany

Intercompany with buf2buf

Simple progress counter

This is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  static void FO_changecompanyDataTransfer(Args _args)
  {
      // Table we want to copy.
      BOM    tableFrom, tableTo;
 
      // Company we want to copy data to.
      str    destinationCompany = "DAT";
 
      // ProgressCounter
      #avifiles
      SysOperationProgress                 oProgress;
      int                                  nTotal;
      #define.TITLE("Copying data...")
      ;
 
      // How many rows to copy, used for the progress
      // counter.
      select count(RecId) from tableFrom;
 
      nTotal    = tableFrom.RecId;
      oProgress = 
      SysOperationProgress::newGeneral(#aviUpdate,
                                           #TITLE,
                                           nTotal);
      tableFrom.clear();
 
      while select tableFrom
      {
 
          changecompany(destinationCompany)
          {
              tableTo = null;
 
              ttsbegin;
 
              buf2buf(tableFrom, tableTo);
              tableTo.insert();
 
              ttscommit;
          }
 
          oProgress.incCount();
      }
 
      oProgress.hide();
  }

How to use it:

  • 1. Select the company you want to copy from in the “Select company accounts” form. You must currently be in the company you want to copy data from.
  • 2. Enter the Table you want to copy, in our example this is the table BOM.(Line 4)
  • 3. Enter the company id of the company you want to copy the data to, in our example we want to copy data to the company account “DAT”.(Line 7)
  • 4. Run the job.

Please use this code responsibly since mistakes can have big effects if you copy data from or/and to the wrong company.

Testing first and double checking before use is the name of the game.

Last 5 posts in Development

One thought on “Copy data between companies

Leave a Reply

Your email address will not be published. Required fields are marked *