Pass Variables to Codeunit.RUN

nverma
Member Posts: 396
Hello,
I am having an issue with the log and maybe someone can help me out. I need to pass the BatchScriptCode field a particular codeunit. But I am not sure how I can do this. I cant use the typical way of doing it, where we create a codeunit variable in the globals, in the codeunit, we can create a function called SetDefault and pass the batchscriptcode. The reason I cant do this because we don't know what the pre-mapping codeunit or mapping codeunit is going to be. This information is going to be determined by looking at DataExchMapping field.
This is how the system is currently calling these codeunit:
CODEUNIT.RUN(DataExchMapping."Pre-Mapping Codeunit" "Rec").
Any help will be appreciated.
I am having an issue with the log and maybe someone can help me out. I need to pass the BatchScriptCode field a particular codeunit. But I am not sure how I can do this. I cant use the typical way of doing it, where we create a codeunit variable in the globals, in the codeunit, we can create a function called SetDefault and pass the batchscriptcode. The reason I cant do this because we don't know what the pre-mapping codeunit or mapping codeunit is going to be. This information is going to be determined by looking at DataExchMapping field.
This is how the system is currently calling these codeunit:
CODEUNIT.RUN(DataExchMapping."Pre-Mapping Codeunit" "Rec").
Any help will be appreciated.
0
Answers
-
You can create a field in Rec variable and populate it before the codeunit.run
0 -
I did have that idea. Instead what I am thinking about doing is creating a dummy field on a setup table and populating it with the batchscriptcode. Once the codeunit is executed, call the setup table to determine the batchscriptcode. At the end of the transaction, clear the field in the setup table.0
-
It is a multi-user environment, but this is needed for a batch processing and its only need when the company is being set up. So only one person will be executing this functionality.0
-
you could do that, but it will add locking issues0
-
you could do that, but it will add locking issues
I am not that concerned about that really. Because this is going to be done before anyone has access to the system. This is going to be done by admin. This is going to be done around the same time as packages are going to be applied to a newly created company.0 -
Hey, nverma.
in my opinion there are two possibilities.
1) Store everything in the Rec. You can send a temporary record too.
2) Store the values you need for the process in another Codeunit with SingleInstance. I like working with SingleInstance Codeunits as they work as a small cache and give you a lot of possibilies. Just make sure to clear the Codeunit before use.
0 -
Hi,
You can also pass the parameters in filters. Set filters on Rec variable, and in the codeunit you can use GETFILTER on each field to read what has been passed in the call. This is a good trick if you cannot modify the table to add a few fields required to pass parameters.
If you Rec variable is a custom table which you can modify then the easiest way is to add a few fields and pass parameters in them, as others already suggested. You don't have to use MODIFY to store values in the database, simple assignment right before CODEUNIT.RUN is OK.
Slawek
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
Before using the filter method, I would really pass the temporary record to use some values. If I need a filter in the function, I would use the getfilter method.0
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