web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Same procedure with different arguments

(0) ShareShare
ReportReport
Posted on by 377

Hi,

I'm trying to understand some logic in the Item Templ. Mgt. codeunit

There is a procedure CreateItemFromTemplate which calls ApplyItemTemplate procedure (line 30)

This procedure is declared twice, with different number of arguments (lines 35 and 40). I'm trying to understand how the system know which one to trigger

I have a sandbox where it calls the first version (2 arguments) which then calls the 2nd version with the 3rd argument set to false

I have another sandbox where it calls directly the 2nd version with the 3rd argument set to true

pastedimage1648586120702v1.png

I have the same question (0)
  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,105 Moderator on at

    This is called procedure overload. And the system will look for a procedure signature that match the parameters that you send to it. If no signature match the parameters you will get an error.

    You can read more about it here:

    docs.microsoft.com/.../devenv-overload-method

  • Juliem Profile Picture
    377 on at

    Thank for your reply. I thought procedure overload meant the same number of arguments with at least one of them with a different type.

    In the case I'm talking about, it's the number of arguments that changes.

    The procedure is being call from the same line of code, with only 2 arguments.

    What would tell the system which one to call.

    The data in the item template is identical in both sandbox

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,105 Moderator on at

    But in AL context it is called overload even when the number of arguments are different.

    So when you call an overloaded procedure in AL you need to make sure that you match one of the overloads with both number of arguments and the type of arguments.

    So the example in your code has two signature one with two records and one with two records and a boolean.

    So if you only have the two records as your argument the first procedure will run, add the boolean and the second procedure will run.

  • Juliem Profile Picture
    377 on at

    This is not the case, as far as I can see, unless I'm missing something

    It's base code, nothing has been modified

    This is the call in both scenario: ApplyItemTemplate(Item, ItemTempl);

    Only 2 arguments

    1 Sandbox goes to the first procedure with 2 arguments. I see in the call stack that it goes from line 30 to line 37, then line 42

    pastedimage1648593991253v2.png

    1 Sandbox goes to the 2nd procedure with 3 arguments. I see in the call stack that it goes from line 30 to line 42

    pastedimage1648593875754v1.png

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,105 Moderator on at

    Then there is definitely something you don't see.

    Data is probably different in your two sandboxes or something else is different that makes the procedures being called different.

    A call with two parameters can not trigger a procedure that requires 3 parameters.

  • Juliem Profile Picture
    377 on at

    But you can see from the screenshots the steps from the debugger, no?

    You clearly see that a 2 parameters call is triggering the 3 parameters procedure

  • YUN ZHU Profile Picture
    95,329 Super User 2025 Season 2 on at

    Hi, you can also set different numbers of arguments in the same procedure.

    For example: https://www.waldo.be/2018/05/29/function-overloading-in-al/

    Hope this also helps.

    Thanks.

    ZHU

  • Inge M. Bruvik Profile Picture
    1,105 Moderator on at
    [quote user="Juliem"]

    Hi,

    I'm trying to understand some logic in the Item Templ. Mgt. codeunit

    There is a procedure CreateItemFromTemplate which calls ApplyItemTemplate procedure (line 30)

    This procedure is declared twice, with different number of arguments (lines 35 and 40). I'm trying to understand how the system know which one to trigger

    I have a sandbox where it calls the first version (2 arguments) which then calls the 2nd version with the 3rd argument set to false

    I have another sandbox where it calls directly the 2nd version with the 3rd argument set to true

    pastedimage1648586120702v1.png

    [/quote]

    Yes, but my understanding us that you can not have the same procedure signature called with different number for parameters.

    So if i say 

    Procedure MyTest (A: record Customer; b: record Vendor);

    begin

    end;

    Procedure MyTest (A: record Customer; b: record Vendor; c: record Item);

    begin

    end;

    My point is that you can never have AL end up executing the first version of the procedure if you have added the record item to the calling parameters,

    It will always execure the procedure that match the parameters it is called with.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,143

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,694 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,067 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans