How to add parameters to a function

Let's modify the codeunit so that the message to be shown to the user will be passed in the function call instead of hardcoding it in the function body itself. From the previous section, you already  know how to access the list of functions. Now, there is only one function we named SayHello. Change its name to ShowMessage and close the C/AL Global window to return to the code editor.

Now, let's add a text parameter to the ShowMessage function. To access the list of function parameters, position the cursor in any line inside the function and choose the View | Locals menu option, or click Ctrl + L. This action opens a C/AL Locals window that contains local declarations for the function. In the Name field of the table, enter a parameter named MessageText and choose its type in the drop-down list in the DataType field. This parameter should be of type Text. The other fields of the table are left blank. The Subtype property is not applicable to text variables, and the blank value of Length means that the length of the text string in unlimited:

 Function parameter declaration

Now, just close the window, and you are good to go; a text parameter can be passed to the function. Note that the function header was also updated. You can see function's parameter in the text editor, although you cannot modify it. Modify the OnRun and ShowMessage functions as follows:

OnRun()
ShowMessage('Just another text message!');

LOCAL ShowMessage(MessageText : Text)
MESSAGE(MessageText);

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.80.94