Running a codeunit automatically

sbillysbilly Member Posts: 231
Hi All,
I have a codeunit that contains many fuction.
I want to schedule only one function of this codeunit to be run automatically, every thing is OK with the NAS.
But I don't know how to configure the Job Queue.
What shall I put in the parameter string of the Job Queue Entry Card.
Thanks.

Comments

  • mohana_cse06mohana_cse06 Member Posts: 5,504
    You need to use the startup parameter JOBQUEUE for the Job Queue to start..
  • sbillysbilly Member Posts: 231
    I set it in the start parameter of the NAS,
    I can run a report with the job schedule,
    but my problem is how to run only a function of codeunit with the job queue.
  • matttraxmatttrax Member Posts: 2,309
    I think you have to setup a separate report or Codeunit to call the specific function you want to run. I guess you could use the same one, assuming there is nothing in the OnRun trigger. You can use the Parameter String and pass a value to the object being called. Then write code based on that parameter value to call your function.
  • ssinglassingla Member Posts: 2,973
    You cannot directly call a function of Codeunit from Job Queue. Either you have to create a new codeunit which can call this function or put a condition in the Codeunit that if NAS then it will execute the function and exit.
    CA Sandeep Singla
    http://ssdynamics.co.in
  • DenSterDenSter Member Posts: 8,307
    ssingla wrote:
    You cannot directly call a function of Codeunit from Job Queue. Either you have to create a new codeunit which can call this function or put a condition in the Codeunit that if NAS then it will execute the function and exit.
    Close, but not quite. You can set up a codeunit to run from the Job Queue, and it will execute the codeunit itself, meaning it will run the OnRun trigger of that codeunit. The codeunit must have a "Job Queue Entry" record as a parameter, so you can set it up to do certain things by way of the value of the "Parameter String" field in the "Job Queue Entry".
  • sbillysbilly Member Posts: 231
    Thanks for replay :)
    If I understand u well : If I ever want to run a function, must call it in OnRun(), It's Okay.
    What I want is how to use the "Parameter String" field in the "Job Queue Entry" to execute my function and not another function that is in the OnRun trigger.
    Thanks
  • DenSterDenSter Member Posts: 8,307
    Use your imagination, you can make it do whatever you need.
  • sbillysbilly Member Posts: 231
    DenSter wrote:
    Use your imagination, you can make it do whatever you need.
    I like ur answers very much :)

    I found it !!!!!!! :D
    This's my solution:
    Case "Parameter String" of
    'param1' : function1;
    'param2 : function2;
    end;
    
  • DenSterDenSter Member Posts: 8,307
    Very nice work :thumbsup:
  • sfriedmansfriedman Member Posts: 8
    Much appreciation for sbilly's question and DenSter's answers:

    I am able to have my nassql instance successfully execute reports for which I have created Job Queue Entries, and this is huge progress for me.

    I am stuck on the Code Unit question. The previous posts seem to imply that:
    - the OnRun() function of the codeunit will always run for the codeunit specified
    - the way to implement the "Parameter String" is to create a global variable within the codeunit called "Parameter String", and then evaluate its contents

    Are these two assumptions correct?

    Problem 1: With no "Parameter String" specified, when my codeunit runs, the Job Queue Entry gets stuck in the "In Process" status and never finishes. The code in OnRun() is not executed.

    Problem 2: I am unsure how to verify if the codeunit global variable is supposed to be titled "Parameter String", "ParameterString", "Parameter", or any other variant.

    Problem 3: Even when I have a "Parameter String" specified on the Job Queue Entry card, the Job Queue Log Entries screen notes: "The codeunit was called with a Job Queue Entry record. It has no parameters."

    In the previous sentence above, does "it" refer to the codeunit having no parameters or the Job Queue Entry having no parameters? Can you discern from my description where I misunderstand this process? Is there a web-based manual I can reference?

    Thanks in advance for any thoughts.
    Cheers-
    Sam
  • sbillysbilly Member Posts: 231
    If I understand what u want :
    U want to run a function in CU with NAS, right?
    That's what u should do:

    U should specify 'Job queue entry' as TableNo property of ur CU witch contains many function.
    Then u write this code in the on run trigger:
    TESTFIELD ("Parameter String");
    CASE "Parameter String" OF
    'param1' : function1;
    'param2' : function2;
    END;
    

    The "Parameter String" isn't a global variable but a field of the 'Job queue entry' table.
    After that u create a Job queue entry card.
    and u fill in the "Parameter String" param1 if u want to execute function1 or param2 if u want to execute function2.

    Hope that it will help u.
    Ur Welcome
    Sbilly
  • sfriedmansfriedman Member Posts: 8
    sbilly,

    Thanks! I just saw your reply today.

    I ended up finding some example code that was exactly what you suggested. It worked!

    Thank you,
    Sam
  • colingbradleycolingbradley Member Posts: 162
    can you share the code?

    NAV 2009 SP1.

    I need to run a CU, (SingleInstance = Yes) that resets any Job Queue Entry where the Status = "In Process".
    The CU has a timer that checks the status every 30 seconds.

    If I run it as a Job Queue and itself is stuck on "In Process", I am then unable to do anything with it except hope that a user will manually reset the job queue entries that need it.

    1. Can I run my CU from CU1 or must I set it up as Job Queue Entry?

    2. I am supposing that the NAS service runs CU1?

    3. If I set it up as a Job Queue, then I need to understand how to use the Parameter string, any suggestions very welcome.

    Thanks in advance,
    Colin
    Experience is what you get when you hoped to get money
  • thegunzothegunzo Member Posts: 274
    I have a simple codeunit that I add to the Job Queue to reset other job queue entries.
    OnRun(VAR Rec : Record "Job Queue Entry")
    JobQueue.SETFILTER(ID,'<>%1',ID);
    IF JobQueue.FINDSET THEN REPEAT
      IF (JobQueue.Status = JobQueue.Status::"In Process") THEN BEGIN
        JobQueue.Status := JobQueue.Status::Ready;
        JobQueue.MODIFY(TRUE);
      END;
    UNTIL JobQueue.NEXT = 0;
    
    ________________________________
    Gunnar Gestsson
    Microsoft Certified IT Professional
    Dynamics NAV MVP
    http://www.dynamics.is
    http://Objects4NAV.com
  • colingbradleycolingbradley Member Posts: 162
    Nice one.
    I have the following but not in the Job Queue:

    OnRun()
    IF ISCLEAR(autNavisionTimer) THEN BEGIN
    CREATE(autNavisionTimer);
    autNavisionTimer.Interval(30 * 1000);
    autNavisionTimer.Enabled(TRUE);
    END;

    autNavisionTimer::Timer(Milliseconds : Integer)
    CLEAR(JobQueueEntry);
    JobQueueEntry.SETRANGE("Recurring Job" , TRUE);
    JobQueueEntry.SETFILTER(Status , '%1', JobQueueEntry.Status::"In Process");
    IF JobQueueEntry.FINDSET THEN BEGIN
    WITH JobQueueEntry DO
    REPEAT
    JobQueueSetup.GET();
    JobQueueSetup."Automation Active" := TRUE;
    IF JobQueueSetup."Send E-Mail Error" THEN
    SendErrorToMail.EMailError(JobQueueEntry);
    LOCKTABLE;
    Status := 0;
    MODIFY;
    UNTIL JobQueueEntry.NEXT = 0
    END;

    I am considering changing a few things such as, what caused the error and how to deal with it.
    To do that, change the Status to "On Hold" and hope that the email will do the trick and get some human intervention.
    Also, if the error is repeated as often as the job is run and it falls over, another email will be sent - that will irritate the recipients.
    Experience is what you get when you hoped to get money
Sign In or Register to comment.