Skip to main content

Notifications

Community site session details

Community site session details

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

Referencing Variable Names

(0) ShareShare
ReportReport
Posted on by 237

Hello,

Is it possible to reference different variables with one AL statement?

For example, Label variables are defined like

Label01: Label 'aaaaa';

Label02: Label 'bbbbb';

Label03: Label 'ccccc';

And instead of referencing each variable with 3 AL lines, referencing like

Value := Labelnn;

(where nn is 01, 02, 03)

I have a feeling that this is not possible, but if anyone knows the solution to this, please advise.

Thank you!

  • adams1124 Profile Picture
    237 on at
    RE: Referencing Variable Names

    Thank you, Zhu.

    I will try as you advised.

  • Verified answer
    YUN ZHU Profile Picture
    83,305 Super User 2025 Season 1 on at
    RE: Referencing Variable Names

    Hi, yes, as Teddy said, it is not possible.

    But if you want to reduce the number of variables, I think arrays are also a good choice.

    For example.

    pastedimage1634522033682v1.png

    Hope this will help.

    Thanks.

    ZHU

  • adams1124 Profile Picture
    237 on at
    RE: Referencing Variable Names

    Thank you, Zhu. I should have been more specific.

    What I wondered if I could do is to reference the label variables in one statement.

    ...

    Label1: Label 'aaaaa';

    Label2: Label 'bbbbb';

    Label3: Label 'ccccc';

    Name: Text;

    n: integer;

    ...

           for n := 1 to 3 do begin

               Name := Labeln;

              (do something using Name)

           end;

    ...

    So the name of the variable needs to be referenced "as variable", like "Labeln".

    I guess it is not possible with AL and in the case above, I need to write the process for each Label variable (Label1, Label2, Label3).

  • adams1124 Profile Picture
    237 on at
    RE: Referencing Variable Names

    Thank you, Teddy.

  • Suggested answer
    YUN ZHU Profile Picture
    83,305 Super User 2025 Season 1 on at
    RE: Referencing Variable Names

    Hi, I think you can try the array.

    A very simple example:

    pastedimage1634514851724v1.png

    Hope this will help.

    Thanks.

  • Verified answer
    Teddy Herryanto (That NAV Guy) Profile Picture
    13,643 Moderator on at
    RE: Referencing Variable Names

    Don't really know why you want to do that.

    Answer is no.

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

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

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 1,174

#2
YUN ZHU Profile Picture

YUN ZHU 1,006 Super User 2025 Season 1

#3
Mansi Soni Profile Picture

Mansi Soni 836

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans