Options

Pass Variables to Codeunit.RUN

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.

Answers

  • Options
    ara3nara3n Member Posts: 9,255
    You can create a field in Rec variable and populate it before the codeunit.run

    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    nvermanverma Member Posts: 396
    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.
  • Options
    nvermanverma Member Posts: 396
    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.
  • Options
    ara3nara3n Member Posts: 9,255
    you could do that, but it will add locking issues
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    nvermanverma Member Posts: 396
    ara3n wrote: »
    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.
  • Options
    pleachim@outlook.compleachim@outlook.com Member Posts: 24
    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.


  • Options
    Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    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-03
  • Options
    pleachim@outlook.compleachim@outlook.com Member Posts: 24
    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.
Sign In or Register to comment.