1

In the context of Powershell and dynamics NAV 2015 there is a function for running codeunits. This provides the Argument parameter. There is no documentation on how to use this parameter or how the used values ​​can be received within the codeunit.

I've tried running the codeunit with an example string, but I can't receive it anywhere in the codeunit. When running the codeunit with the MethodName parameter and arguments, I get the following error:

Invoke-NAVCodeunit : Method 'Codeunit50060.UpdateStatus(number of arguments: 1), with matching argument types.' not found.
At line:2 char:1
+ Invoke-NAVCodeunit -ServerInstance navisiontest -CompanyName d-velop  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (0:Int32) [Invoke-NAVCodeunit], FaultException`1
    + FullyQualifiedErrorId : MicrosoftDynamicsNavServer$navisiontest,Microsoft.Dynamics.Nav.Management.Cmdlets.InvokeNavCodeunit

This is my codeunit: codeunit

Flo VR
  • 11
  • 2
  • Does this help : https://community.dynamics.com/nav/f/microsoft-dynamics-nav-forum/274106/how-to-invoke-navcodunit-with-navuserpassword?force_isolation=true – jdweng Dec 06 '22 at 10:45
  • 1
    You procedure is LOCAL. Remove this to make the procedure public, and can then be called from outside of the codeunit. – ian_scho Dec 07 '22 at 06:52

1 Answers1

0

If you call the codeunit, it will run the code in OnRun() function only. If your OnRun() calls to another method, you must set the method Local property to "No" in designer. Go to Development tool -> choose the codeunit -> go to Design -> tab Function -> select function you need to run -> click Properties buttion -> set Local to 'No' That is also helpful when you want to call the method inside codeunit directly without OnRun() defined.

then in powershell, you can call with parameters as following example:

Invoke-NAVCodeunit SampleInstance -CodeunitId 500001 -MethodName 'SampleMethod' -Argument 'SampleArg'

Hai Nguyen
  • 25
  • 4