CU by Id and running functions

rixrixrixrix Member Posts: 121
Hello

Please, is it somehow possible to run function defined in codeunit when I only have ID of Codeunit ?

I can run codeunit by CODEUNIT.RUN(Id) ,but I do not know how to run function inside it .... it is used to run multiple different codeunits so I do not want to define them as variables.

I need to pass some variable to that codeunit so i wanted to do it by calling it's "SetVariable" function

Thank u in advance

Comments

  • koubekkoubek Member Posts: 84
    It is not possible to run any user defined function of the codeunit until you have the codeunit defined as a variable. NAV allow you to only the trigger "OnRun()" without instantiation of the codeunit as a variable.
  • rixrixrixrix Member Posts: 121
    Thanx :-(

    So is there another way how can I solve my problem ?:

    I have in Job scheduler several jobs which run the same CODEUNIT.
    I have field Parameters which are different for each Job.

    I would like to, in OnRun() function of codeunit to find out which Job "runned" the codeunit so I can read parameters from specific line.

    Thanx
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    That's easy: Add a parameter field to table 472 "Job Queue Entry", table 474 "Job Queue Log Entry" and form 673 "Job Queue Entry Card". Add code in codeunit 448 "Job Queue Dispacher", function "InsertLogEntry" to save the parameter field in the log.

    Now you can check that parameter in the OnRun-trigger of your codeunit, to execute the wanted function.
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • koubekkoubek Member Posts: 84
    When you run any codeunit you have to pass Job Queue Entry record as a parameter. You can use Parameter String field to pass in a parameter and than you can decide by code which function or another object you will executed based on the value of the parameter...
  • rixrixrixrix Member Posts: 121
    Luc:
    Hmm, no such tables here ... I have v5.1 tech update .. should it be here?
    I have only: 5980-Job Scheduler Mgt. Setup,5981-Job Scheduler Setup,5982-Job Scheduler Log

    Koubek:
    I was thinking about this, but what if
    a) Some codeunit is not defined with Record parameter in OnRun()
    b) Some codeunit has defined different Record type as input parameter ... then I can not use the one from JScheduler
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    You can only execute codeunits which are prepared for use by the Job Queue module. It won't be possible to run every codeunit which resides in your NAV database, without modification.

    You apparently are using an older version of the Job Queue module.
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • rixrixrixrix Member Posts: 121
    I just wanted to have some "codeproof" simple solution ....

    I will probably try to use Koubek's solution, because all CU's which are runned by JScheduler was currently runned without any Rec parameter so I suppose tha do not have defined any "table" in Properties.

    So if there is not problem with calling such CU's with parameter It can work ... I will add "table" property only to those which I will modify to use it ....
  • koubekkoubek Member Posts: 84
    As Luc correctly said You can use only codeunit with the "Job Queue Entry" record defined. I understand what you exactly need but you have to handle it within this entry codeunit (you can trigger another code from another CU from the entry CU but you have to do it by your code). It is not so complicated :wink:
  • rixrixrixrix Member Posts: 121
    I do not have "Job Queue Entry" table but I suppose you mean record in "Job Scheduler Setup" in my case

    If so, of course, it will be defined there, but I probably do not understand what u meant by triggering CU from another CU (I mean to solve my problem)

    If there is no other way to pass JOB_ID directly to CU ,only by Record param I see only way to store it somewhere and then find it ... but it is not "bulletproof" because I am not able to generate some unique identifier which will be known to both CUs
    (Maybe it will work in 99% nut not 100% :-) )
  • koubekkoubek Member Posts: 84
    You can use for example formated RecordID and restore it then within your entry codeunit.
  • rixrixrixrix Member Posts: 121
    I do not understand .. can u be please more specific ?

    I have

    CU1(JSchRec):
    CODEUNIT.RUN(JSchRec.Codeunit_ID);

    CU2():
    OnRun():
  • rixrixrixrix Member Posts: 121
    I will try something else probably. Thank you all
Sign In or Register to comment.