Job Scheduler

CindyPretCindyPret Member Posts: 15
edited 2008-05-06 in Navision Attain
Can Navision's Job Scheduler run automatically withou a user pressing the start button?

Comments

  • garakgarak Member Posts: 3,263
    if you use a NAS for sheduling, yes
    Do you make it right, it works too!
  • ara3nara3n Member Posts: 9,256
    You have to move the code from the form to a codeunit. and add code to CU 1 to start the a timer that will call the new CodeUnit.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Alex_ChowAlex_Chow Member Posts: 5,063
    The problem with NAS is that you will not be able to run anything that returns a output... :(
  • CindyPretCindyPret Member Posts: 15
    Thank you!
  • navuser1navuser1 Member Posts: 1,329
    ara3n wrote:
    You have to move the code from the form to a codeunit. and add code to CU 1 to start the a timer that will call the new CodeUnit.

    Please explain how to start timer..........
    Now or Never
  • ara3nara3n Member Posts: 9,256
    Here is the Single Instance CU that would start from CU 1.
    OnRun()
    JobSchedMgtSetup.GET;
    JobSchedMgtSetup.TESTFIELD("Shut Down Time");
    
    IF ISCLEAR(Timer) THEN
      CREATE(Timer);
    
    Timer.StartTimer(6000);
    
    IsRunning := TRUE;
    
    CodeUnitIsRunning() : Boolean
    EXIT(IsRunning);
    
    Code()
    IF NOT JobSchedMgtSetup.GET THEN
      ERROR(Text000,JobSchedMgtSetup.TABLECAPTION);
    IF (NOT JobSchedMgtSetup."Log Scheduler Actions") THEN
      EXIT;
    CheckAndRunScheduler;
    
    CheckAndRunScheduler()
    SELECTLATESTVERSION;
    JobSchedSetup2.LOCKTABLE;
    JobSchedSetup2.RESET;
    JobSchedSetup2.SETCURRENTKEY("Next Check Date","Next Check Time");
    JobSchedSetup2.SETFILTER("Next Check Date",'<>%1',0D);
    JobSchedSetup2.SETRANGE(Enabled,TRUE);
    IF JobSchedSetup2.FIND('-') THEN REPEAT
      JobSchedSetup := JobSchedSetup2;
      IF RunNow(JobSchedSetup."Next Check Date",JobSchedSetup."Next Check Time",JobSchedSetup) THEN
        IF AllObj.GET(JobSchedSetup."Object Type",JobSchedSetup."Object No.") THEN BEGIN
          COMMIT;
          IF JobSchedSetup."Error Handling" = JobSchedSetup."Error Handling"::"Mark as Error and Stop" THEN BEGIN
    
          CASE JobSchedSetup."Object Type" OF
            JobSchedSetup."Object Type"::Report: REPORT.RUNMODAL(JobSchedSetup."Object No.",FALSE,FALSE);
            JobSchedSetup."Object Type"::Dataport: DATAPORT.RUNMODAL(JobSchedSetup."Object No.",FALSE);
            JobSchedSetup."Object Type"::Codeunit: CODEUNIT.RUN(JobSchedSetup."Object No.");
          END;
            COMMIT;
            JobSchedSetup.LOCKTABLE;
            JobSchedSetup.GET(JobSchedSetup.ID);
            JobSchedSetup."Message Text" := 'Processed successfully.';
            JobSchedSetup."Last DateTime Run" := CURRENTDATETIME;
            NewDateAndTime(JobSchedSetup);
            IF JobSchedSetup.MODIFY THEN;
            COMMIT;
    
          END ELSE BEGIN
    
           IF RunObjectFromJobSched.RUN(JobSchedSetup) THEN BEGIN
            COMMIT;
            JobSchedSetup.LOCKTABLE;
            JobSchedSetup.GET(JobSchedSetup.ID);
            JobSchedSetup."Message Text" := 'Processed successfully.';
            JobSchedSetup."Last DateTime Run" := CURRENTDATETIME;
            NewDateAndTime(JobSchedSetup);
            IF JobSchedSetup.MODIFY THEN;
            COMMIT;
           END ELSE BEGIN
            JobSchedSetup.LOCKTABLE;
            JobSchedSetup.GET(JobSchedSetup.ID);
            JobSchedSetup."Message Text" := Text013;
            JobSchedSetup."Last DateTime Run" := CURRENTDATETIME;
            IF JobSchedSetup.MODIFY THEN;
            COMMIT;
           END;
          END;
        END;
    UNTIL JobSchedSetup2.NEXT = 0;
    
    RunNow(RunDate : Date;RunTime : Time;JobSchedSetup : Record "Job Scheduler Setup") : Boolean
    IF JobSchedSetup."Run Status" = JobSchedSetup."Run Status"::"Special Order" THEN
      EXIT(TRUE);
    
    IF (RunDate = 0D) OR (RunTime = 0T) THEN
      EXIT(FALSE);
    
    IF ((TODAY - RunDate) * 24) + ((TIME - RunTime) / 3600000) > 0 THEN BEGIN
      CASE DATE2DWY(TODAY,1) OF
        1:
          IF JobSchedSetup."Valid on Mondays" THEN
            EXIT(CheckTimeLimit(JobSchedSetup))
          ELSE
            EXIT(FALSE);
        2:
          IF JobSchedSetup."Valid on Tuesdays" THEN
            EXIT(CheckTimeLimit(JobSchedSetup))
          ELSE
            EXIT(FALSE);
        3:
          IF JobSchedSetup."Valid on Wednesdays" THEN
            EXIT(CheckTimeLimit(JobSchedSetup))
          ELSE
            EXIT(FALSE);
        4:
          IF JobSchedSetup."Valid on Thursdays" THEN
            EXIT(CheckTimeLimit(JobSchedSetup))
          ELSE
            EXIT(FALSE);
        5:
          IF JobSchedSetup."Valid on Fridays" THEN
            EXIT(CheckTimeLimit(JobSchedSetup))
          ELSE
            EXIT(FALSE);
        6:
          IF JobSchedSetup."Valid on Saturdays" THEN
            EXIT(CheckTimeLimit(JobSchedSetup))
          ELSE
            EXIT(FALSE);
        7:
          IF JobSchedSetup."Valid on Sundays" THEN
            EXIT(CheckTimeLimit(JobSchedSetup))
          ELSE
            EXIT(FALSE);
        ELSE
          EXIT(FALSE);
      END;
    END ELSE
      EXIT(FALSE);
    
    CheckTimeLimit(JobSchedSetup : Record "Job Scheduler Setup") : Boolean
    IF (JobSchedSetup."Starting Time" = 0T) OR (JobSchedSetup."Ending Time" = 0T) THEN
      EXIT(TRUE);
    
    WTime := TIME;
    IF (WTime >= JobSchedSetup."Starting Time") AND (WTime <= JobSchedSetup."Ending Time") THEN
      EXIT(TRUE)
    ELSE
      EXIT(FALSE);
    
    NewDateAndTime(VAR JobSchedSetup2 : Record "Job Scheduler Setup")
    JobSchedSetup2."Last Date Checked" := TODAY;
    JobSchedSetup2."Last Time Checked" := TIME;
    IF JobSchedSetup2."Run Status" <> JobSchedSetup2."Run Status"::"Special Order" THEN
      RunObjectFromJobSched.CalcNewDateTime(
        JobSchedSetup2."Next Check Date",JobSchedSetup2."Next Check Time",
        JobSchedSetup2."Time Between Check",JobSchedSetup2."Unit of Measure");
    
    Timer::TimerEvent()
    Code;
    COMMIT;
    

    All the variables have been copied from Form.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • CindyPretCindyPret Member Posts: 15
    Thank you
  • ara3nara3n Member Posts: 9,256
    you are welcome.
    Ahmed Rashed Amini
    Independent Consultant/Developer


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