Home

Thursday, December 11, 2014

Copy data between companies

static void FO_changecompanyDataTransfer(Args _args)
  {
      // Table we want to copy.
      salesTable    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.

No comments:

Post a Comment