Open another company from C/AL code

victorMvictorM Member Posts: 24
Dear All,

Hi, I have a problem now, does anyone know, how to open company from c/al code? I have 32 company in my office in one database, I need to run dataport in each company automatically one by one to import data from the outside, I don't want to use CHANGECOMPANY, because VALIDATE function just working in current company.

If anyone have some idea, share it to me please.. Thanks for help

Answers

  • kinekine Member Posts: 12,562
    You can do it only in few ways:

    1) Send the keystrokes through SendKeys (Something like "Ctrl+O""Home""Down""Down""Enter") but still you need to solve how to keep your code running even when you are changing company (it will not allow you to run the code when you are changing company, the transaction must end before you change it). And after the change you need to run the object somehow.
    2) You can start new client within your code with the correct parameters, but you need to solve how to run the dataport when you open the company...
    3) Create webservice for each company (how depends on version you are using) and call the function for each one...
    4) Use NAS for each company and run the import from there...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • victorMvictorM Member Posts: 24
    Wow that's amazing kine, thanks a lot, maybe I'll choose option 1 or 4
  • David_SingletonDavid_Singleton Member Posts: 5,479
    kine wrote:
    You can do it only in few ways:

    1) Send the keystrokes through SendKeys (Something like "Ctrl+O""Home""Down""Down""Enter") but still you need to solve how to keep your code running even when you are changing company (it will not allow you to run the code when you are changing company, the transaction must end before you change it). And after the change you need to run the object somehow.
    2) You can start new client within your code with the correct parameters, but you need to solve how to run the dataport when you open the company...
    3) Create webservice for each company (how depends on version you are using) and call the function for each one...
    4) Use NAS for each company and run the import from there...

    I think 3 and 4 are the real options. :wink:

    Send keys does not belong in an ERP environment.
    David Singleton
Sign In or Register to comment.