Change Client company in Dynamics NAV Classic with C/AL

Full article at my blog: http://mibuso.com/blogs/rikardh/2012/12/13/cal-change-company-dynamics-nav-classic/

If the database has multiply companies the user sometimes has to change company. There are no functions i C/AL to change company so we have to use windows script host.

  1. Create a codeunit

changecompany1b.PNG

We use 2 automation variables, 1 timer and 1 script host. Create a function with 1 text parameter. Init the automation variables. Send CTRL+O (open company) keyboard combination. Set the timer to 0,5 seconds and activate it.

Then the timer runs it sends the company name as keyboard hits, and followed by to ENTER keys.

When the company name is written with keyboard it will bring up the search form and will search for the company name, the first enter press closes the search form and the other enter opens the company.

We have to use a timer to allow NAV to open the open company dialog before we try to change company.

  1. Test form

changecompany0.PNG

A simple form to test the codeunit.

changecompany2.PNG

Declare the codeunit as a global variable, this is necessary if it is declared as a local it would not be active long enough for the timer to run.