CU by Id and running functions

rixrix
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
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
0
Comments
-
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.0
-
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.
Thanx0 -
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)0 -
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...0
-
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 JScheduler0 -
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)0 -
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 ....0 -
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 complicated0
-
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% :-) )0 -
You can use for example formated RecordID and restore it then within your entry codeunit.0
-
I do not understand .. can u be please more specific ?
I have
CU1(JSchRec):
CODEUNIT.RUN(JSchRec.Codeunit_ID);
CU2():
OnRun():0 -
I will try something else probably. Thank you all0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions