How to have a codeunit with a onrun parameter

SogSog Member Posts: 1,023
When trying to add a parameter in the onrun function of a codeunit in design it is not possible.
But when it is wanted to have a parameter you can export the object in txt format,
add in the properties section just before the onrun section the parameter and import it again.
(look at "<-- this is the parameter" in the codesnippet)
So far I've only tested it with a record as a variable. The correct syntax for other datatypes is so far unkown to me.
OBJECT Codeunit 50000 test
{
  OBJECT-PROPERTIES
  {
    Date=25/05/09;
    Time=[10:31:00];
    Modified=No;
    Version List=;
  }
  PROPERTIES
  {
    TableNo=36;   <- this is the parameter (in this case table sales header)
    OnRun=BEGIN
          END;

  }
|Pressing F1 is so much faster than opening your browser|
|To-Increase|

Answers

  • DenSterDenSter Member Posts: 8,304
    It's not possible to add anything other than a record variable as a parameter to a codeunit. In the object designer this is done in the codeunit properties, where you select the table from the table list. There's no need to export as text and then modify the text file.
  • krikikriki Member, Moderator Posts: 9,110
    [Topic moved from 'NAV Tips & Tricks' forum to 'NAV/Navision' forum]
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • ta5ta5 Member Posts: 1,164
    DenSter wrote:
    It's not possible to add anything other than a record variable as a parameter to a codeunit.

    As DenSter quoted, you only can use a record as parameter. For special needs you can use one of these methods:
    - Create a special record only for the parameters
    - Before calling the run method calling a user defined function (called setParams for example) to set one or more global variables of the the codeunit. These globals can be used afterwords. Of course the globals will be reset if the variable of the codeunit goes out of scope.

    Hope this helps
    Thomas
  • SogSog Member Posts: 1,023
    oh, and here I was thinking I discovered something that was not implemented in the designer.
    I guess I've been a little bit to optimistic (or pessimistic, depends how you look at it)
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • David_SingletonDavid_Singleton Member Posts: 5,479
    Sog wrote:
    oh, and here I was thinking I discovered something that was not implemented in the designer.
    I guess I've been a little bit to optimistic (or pessimistic, depends how you look at it)

    Even if you had found something that the NAV PG missed, would you really want to use an unsupported feature like this in a live environment?
    David Singleton
  • DenSterDenSter Member Posts: 8,304
    Sog wrote:
    oh, and here I was thinking I discovered something that was not implemented in the designer.
    I guess I've been a little bit to optimistic (or pessimistic, depends how you look at it)
    Nice try though, and thanks for thinking about sharing your discovery, that shows a good community spirit. Feel free to share these things when you discover them, because every once in a while you come across something that's not supposed to be there :mrgreen:
Sign In or Register to comment.