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

Announcements

News and Announcements icon
Community site session details

Community site session details

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

How to make a codeunit procedure return a value ?

(0) ShareShare
ReportReport
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
I have the same question (0)
  • Verified answer
    Mohana Yadav Profile Picture
    61,242 Super User 2026 Season 1 on at

    procedure AdresseVisible():Boolean

    you have to declare a return variable in function

  • Verified answer
    Chameera Kavinda Profile Picture
    510 on at

    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

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 621 Super User 2026 Season 1

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 445 Most Valuable Professional

#3
YUN ZHU Profile Picture

YUN ZHU 366 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans