Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Answered

How to make a codeunit procedure return a value ?

Posted on by 215

Hello !

I'm learning AL development for 1 week, and I'm facing a pretty simple problem : how do I write a codeunit procedure that returns a value when it's called in pageExtension ? I've looked into the Microsoft documentation here : https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-al-methods But it only says that it can return a value, not how to do it.

What I'm trying to do is to call from a pageExtension a codeunit procedure returning a boolean value to switch the Visible property of a field to False. Here is my code : 

pageextension 8007852 CustomerCardFieldCheckExt extends "Customer Card"
{
    layout
    {
        modify(Address)
        {
            Visible = CustomerNameCheck2.AdresseVisible();
        }
    }
    var
        CustomerNameCheck2: Codeunit CustomerNameCheck2;
}
codeunit 8007853 CustomerNameCheck2
{
    var
        Pw_Visible: Boolean;
    procedure AdresseVisible()

    begin
        Pw_Visible := false;
    end;
}
PW_Visible is a global boolean variable, AdresseVisible() is a global procedure, so why does my pageExt shows the error "the expression must be of Boolean type" ? Is it because a procedure is not a boolean (even if it returns one) ? Or because my procedure doesn't return anything ?
Thank you for your help, and sorry if it is a very low level question.
Pierre
Categories:
  • Verified answer
    Chameera Kavinda Profile Picture
    Chameera Kavinda 510 on at
    RE: How to make a codeunit procedure return a value ?

    Hi,

    This is how define the return value of a procedure. What is the value assigned to Pw_Visible variable is returning from the AdressVisible procedure.

    4048.Capture.PNG

  • Verified answer
    Mohana Yadav Profile Picture
    Mohana Yadav 58,864 Super User 2024 Season 2 on at
    RE: How to make a codeunit procedure return a value ?

    procedure AdresseVisible():Boolean

    you have to declare a return variable in function

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 16th

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,339 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,177 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans