web
You’re offline. This is a read only version of the page.
close
Skip to main content
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
    Chameera Kavinda Profile Picture
    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
    60,941 Super User 2025 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

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 4,304

#2
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 4,045

#3
Sumit Singh Profile Picture

Sumit Singh 2,970

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans