Run codeunit with -consolemode, how to pass parameters?

primeapprimeap Member Posts: 37
Id like to execute a specific function instead of CODEUNIT.RUN. Is this possible?

Best Answer

Answers

  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    As I understand I probably want to be able to call a function on a codeunit defined at a run time, CODEUNIT.RUN(number_coming_from_some_setup_table), without declaring the actual codeunit as a variable?)

    In NAV 2016+ you can get similar functionality using events. In calling code define publisher function, and call that function (instead of CODEUNIT.RUN), and in called codeunit define a subscriber subscribing to the publisher function in calling codeunit.

    You would probably need some extra logic to ensure that only one subscriber executes desired code (manual binding or smth)

    In older versions (without events) it is not possible.

    You could try to mimic the behavior by calling the CODEUNIT.RUN on a record, and depending on the values passes call different functions, but at the end of it you wll require a place where called codeunit is defined as a variable anyway - so you would have to know its details at design time.
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • primeapprimeap Member Posts: 37
    No i mean from the cmd shell with Flag -consolemode
  • krikikriki Member, Moderator Posts: 9,096
    That way it is not possible. But you can declare your codeunit as a webservice and then you can call functions in that codeunit using PoSh https://mibuso.com/howtos/how-to-use-powershell-to-test-your-nav-webservice
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.