Options

Run codeunit from outside NAV

cernstcernst Member Posts: 280
I've seen some post to run codeunits from outside NAV but they all use som kind of listener.
Is there any way to run a codeunit from outside NAV without using any automations that listen for events?
_____________________
NAV Freelance Consultant

Comments

  • Options
    rdebathrdebath Member Posts: 383
    Only by starting Navision itself.

    eg:
    "C:\Program Files\Navision\5.01\finsql.exe" ID=RUN-C50099,servername=NAVSVR,database=Navision,ntauthentication=Yes,company=TVision Technology Ltd
    

    Then in codeunit 1 at the end of Function "LogInStart"
    IF CODEUNIT.RUN(CODEUNIT::"Autostart control") THEN ;
    

    Then in the OnRun of codeunit "Autostart control"
    I := STRPOS(UPPERCASE(COMMANDLINE), 'ID=');
    IF I = 0 THEN EXIT ELSE BEGIN
      Str := COPYSTR(COMMANDLINE, I+3);
      I := STRPOS(Str, ',');
      IF I > 0 THEN BEGIN
        IF I > 1 THEN
          Str := COPYSTR(Str, 1, I-1)
        ELSE
          Str := '';
      END;
      I := STRPOS(Str, '-C');
      IF I = 0 THEN EXIT;
      Str := COPYSTR(Str, I+2);
      IF NOT EVALUATE(CodeunitNo, Str) THEN
        EXIT;
    
      CODEUNIT.RUN(CodeunitNo);
    END;
    

    The problem, of course, is exiting Navision once the codeunit has finished. Perhaps you can do some sendkeys stuff to simulate an Alt-F4. I have a few bits of code that will crash Navision ... but that's not very nice. :)

    More likely a better solution is to look for an automation and start Navision if it's not there before trying again.
  • Options
    cernstcernst Member Posts: 280
    Found this one http://techblog.byllemos.com/?p=42 can start a form and thats ok for my current need.
    Thx all.
    _____________________
    NAV Freelance Consultant
Sign In or Register to comment.