Optimizing Tables in Job Scheduler

ara3nara3n Member Posts: 9,256
edited 2009-02-13 in NAV Tips & Tricks
Hello Here is a form that does optemization based on script. Import it as a form, compile it. Optemize is a table with PK of "Table ID". In Optemize table you specify the tables you want to optemize. The form runs on a timer that excecutes the script. Enjoy .

OBJECT Table 50009 optemize
{
  OBJECT-PROPERTIES
  {
    Date=03/02/06;
    Time=[ 8:06:17 PM];
    Modified=Yes;
    Version List=;
  }
  PROPERTIES
  {
  }
  FIELDS
  {
    { 1   ;   ;Table ID            ;Integer        }
  }
  KEYS
  {
    {    ;Table ID                                 }
  }
  CODE
  {

    BEGIN
    END.
  }
}


OBJECT Form 50009 optemize
{
  OBJECT-PROPERTIES
  {
    Date=03/02/06;
    Time=10:30:27 PM;
    Modified=Yes;
    Version List=;
  }
  PROPERTIES
  {
    Width=8000;
    Height=8000;
    Visible=No;
    TimerInterval=150;
    OnOpenForm=BEGIN
                 IF ISCLEAR(wscript) THEN
                   CREATE(wscript);
               END;

    OnQueryCloseForm=BEGIN
                       IF State = 100 THEN
                         EXIT(FALSE)
                       ELSE
                         EXIT(TRUE);
                     END;

    OnTimer=BEGIN
              IF State = 0 THEN BEGIN
                 IF NOT Optemize.FIND('-') THEN
                   CurrForm.CLOSE;
                 tableinformation.SETRANGE("Table No.",Optemize."Table ID");
                 IF tableinformation.FIND('-') THEN BEGIN
                   State := 2;
                   EXIT;
                 END ELSE
                   State := 1
              END;

              IF State = 1 THEN BEGIN
                IF Optemize.NEXT = 0 THEN
                   CurrForm.CLOSE;
                 tableinformation.SETRANGE("Table No.",Optemize."Table ID");
                 IF tableinformation.FIND('-') THEN BEGIN
                    State := 2;
                 END ELSE BEGIN
                    State := 0;
                 END;

              END;

              IF State = 2 THEN
                wscript.SendKeys('%f');
              IF State = 3 THEN
                wscript.SendKeys('b');
              IF State = 4 THEN
                wscript.SendKeys('i');
              IF State = 5 THEN
                wscript.SendKeys('%B');
              IF State = 6 THEN
                wscript.SendKeys('+{F7}');

              IF State = 7 THEN
                wscript.SendKeys('table no.');

              IF State = 8 THEN
                wscript.SendKeys('{TAB}');
              IF State = 9 THEN
                wscript.SendKeys(FORMAT(Optemize."Table ID"));
              IF State = 10 THEN
                wscript.SendKeys('^{DOWN}');
              IF State = 11 THEN
                wscript.SendKeys('{ENTER}');
              IF State = 12 THEN
                wscript.SendKeys('^a');
              IF State = 13 THEN BEGIN
                wscript.SendKeys('%o');
                wscript.SendKeys('y');
              END;

              IF State = 100 THEN BEGIN
                wscript.SendKeys('{ESC}');
                wscript.SendKeys('{ESC}');
                wscript.SendKeys('{ESC}');

              END;

              IF State = 100 THEN
                State := 0;

              State += 1;
            END;

  }
  CONTROLS
  {
  }
  CODE
  {
    VAR
      State@1000000000 : Integer;
      wscript@1000000001 : Automation "{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B} 1.0:{72C24DD5-D70A-438B-8A42-98424B88AFB8}:'Windows Script Host Object Model'.WshShell";
      Optemize@1000000002 : Record 50009;
      tableinformation@1000000003 : Record 2000000028;
      var@1000000004 : Variant;

    BEGIN
    END.
  }
}

Ahmed Rashed Amini
Independent Consultant/Developer


blog: https://dynamicsuser.net/nav/b/ara3n

Comments

  • kishi_gkishi_g Member Posts: 162
    Hi.
    The script is very nice... By seeing ur code i got one doubt. how can i open the form (like sales order form) and how can i press f3 and how can i select sell to customer no(like first customer)( in script press f6 and select customer and press ok ). This procedure how can i do that???





    Regards,
    kishore...
  • garakgarak Member Posts: 3,263
    @kishi_g: Search the forum for Sendkeys. It's very simple.
    Do you make it right, it works too!
  • kishi_gkishi_g Member Posts: 162
    Hi Garak,
    Thanks for ur reply. Iam still searching on mibuso for open the form and lookup(f6). i didnt find the solution.

    Plz help me.


    Thanks & regards,
    kishore...
  • kishi_gkishi_g Member Posts: 162
    I want to open the form(Sales Order) automatically. and i didnt put any cusrsor on the form. After opening the form it will create new record by using F3( Using Sendkeys) and after that will it go to the sell to customer and go to lookup(f6) and take the first customer. Is thispossible by using sendkeys???



    Thanks & Regards,
    kishore...
  • iqbalmadiqbalmad Member Posts: 179
    hi ara3n..

    i created the optimize table and form as mentioned above..

    when i schedule the form to b run at a time, it does not work.. do u know y??

    is there any specific setup to be done?

    in the log file, it does tell me that the process has succeeded.. but i dnt see it happen
  • ara3nara3n Member Posts: 9,256
    what do you mean you schedule to run the form? When you run it manually does go through and optimizes the table?
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • iqbalmadiqbalmad Member Posts: 179
    i wanted to schedule the optimisation of tables through the job scheduler in navision.

    i created a report where i put this code BatchProcessing.RUN; BatchProcessing being the form (optemize in your example)where we put the codes.

    thus i jus sceduled to run the report at a certain time.

    it doesnt work :cry:

    if i run it manually, it runs smoothly...
  • ara3nara3n Member Posts: 9,256
    it runs from a form with a timer. I don't think you can do it from a report.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • iqbalmadiqbalmad Member Posts: 179
    well , wat is the use of passing through a timer to optimise tables..??
  • ara3nara3n Member Posts: 9,256
    with the timer, you get an event type of trigger and allow the control to be released after each call. That way the shortcut keys pressed can happen and Navision things that a user is pressing the keyboard.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
Sign In or Register to comment.