Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV forum
Answered

How to add optional parameter to a function

Posted on by 445

Hi 

I have a function in Business Central. And I want to add an optional parameter to it. 

procedure PostSalesOrder(var SalesOrder: Record "Sales Header"): Boolean


  • SU-07061748-0 Profile Picture
    SU-07061748-0 11 on at
    How to add optional parameter to a function
    Simple.
     
     
    You can overload the function with different parameters.
  • ManishS Profile Picture
    ManishS 6,578 on at
    RE: How to add optional parameter to a function

    What is the functioning of that additional parameter.

  • Suggested answer
    Yuri Mishin Profile Picture
    Yuri Mishin 20 on at
    RE: How to add optional parameter to a function

    You can overload functions. Define a new function with the same name an additional parameters, something like this:

    procedure PostSalesOrder(var SalesOrder: Record "Sales Header"; OptionalParam: Integer) Result: Boolean

    begin

       // Preprocess your OptionalParam here (i.e. store it in a global variable in order to access it in original function)

       Result := PostSalesOrder(SalesOrder);

       // Postprocess your OptionalParam here

    end;

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to add optional parameter to a function

    I think you dont want to touch this function. My suggest create a new function with this paramater / parameters.

  • Suggested answer
    Stefano Demiliani Profile Picture
    Stefano Demiliani 37,160 on at
    RE: How to add optional parameter to a function

    There are no optional parameters in C/SIDE and AL. If your function has two parameters, you need to pass two values. In your code you can test if they are empty or not.

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,252 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,089 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans