microsoft / AL

Home of the Dynamics 365 Business Central AL Language extension for Visual Studio Code. Used to track issues regarding the latest version of the AL compiler and developer tools available in the Visual Studio Code Marketplace or as part of the AL Developer Preview builds for Dynamics 365 Business Central.
MIT License
728 stars 241 forks source link

a not tryfunction was made to TryFunction, if his result is used as parameter for a Tryfunction. #7595

Closed wgross92 closed 9 months ago

wgross92 commented 9 months ago

Situation: The result of procedure A is entered directly as a parameter in procedure B. Procedure B is a TryFunction. Procedure A is not a TryFunction. Result of procedure B is handelt with 'if' or asign to a boolean. However, if A executes a DB operation, a server error occurs because A is a TryFunction. Only its return was taken as a parameter.

Example:

page 50000 MyPage
{
    PageType = Card;
    ApplicationArea = All;
    UsageCategory = Administration;

    actions
    {
        area(Processing)
        {
            action(TestTryFunction)
            {
                trigger OnAction()
                var
                    name: text;
                    myresult: boolean;
                begin
                    //This works ok.
                    MyTryFunction(InsertNewContact('xx100'));

                    //This also works
                    name := InsertNewContact('xx101');
                    if MyTryFunction(name) then;

                    //This Trow Error to Eventlog that InsertNewContact is a try function
                    if MyTryFunction(InsertNewContact('xx102')) then;

                    //This also throw an error
                    myresult := MyTryFunction(InsertNewContact('xx102'));
                end;
            }
        }
    }

    local procedure InsertNewContact(Code: Code[20]): Text
    var
        Cont: Record Contact;
    begin
        Cont.Init();
        Cont."No." := Code;
        Cont.Insert();
        Exit('Hello');
    end;

    [TryFunction]
    local procedure MyTryFunction(name: Text)
    begin
        if (name.Contains('')) then;
    end;

}
qutreson commented 9 months ago

Let's get the issue to a team who will fix and backport it, as this repository is only for issues related to the AL compiler in latest developer preview environment for Dynamics 365 Business Central. We suggest that you open a support case or file a bug in Collaborate, to ensure that all Business Central users benefit from your catch as soon as possible.

To open a support case, you can:

If you file the bug in Collaborate, remember to include steps to reproduce the issue, and the Business Central build number and country version you're using.