Skip to main content
Post a question

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Answered

How to make a codeunit procedure return a value ?

Like (0) ShareShare
ReportReport
Posted on 2 Jul 2020 09:17:26 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
  • Verified answer
    Chameera Kavinda Profile Picture
    Chameera Kavinda 510 on 02 Jul 2020 at 10:41:09
    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 60,054 Super User 2024 Season 2 on 02 Jul 2020 at 10:35:30
    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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,784 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,476 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans
Loading started
Loading complete