Boost Your Productivity with AL/BC – AL Variable Helper

Boost Your Productivity with AL/BC – AL Variable Helper

This is the first post of the blog post series “Boost Your Productivity with AL and Business Central”. If you want to know more about what this series is about and why I created it, you can checkout this post. Today’s post will feature the AL Variable Helper by Rasmus Aaen. According to his own readme file, it provides the following features:

  • Easy variable assignment
  • Go to global/local variables – like in the C/SIDE environment.
  • Sort Variables
  • Fix keyword casing

Let’s checkout what it does.

Easy Variable Assignment

Coming from C/SIDE, you are probably used to using a separate window to declare local or global variables. It is a bit different in AL. Like in most other languages that I know, you instead declare your variables in the code.

The var section of a procedure or trigger is used for this purpose:

Unfortunately, there is no standard functionality to declare a record variable in a fast way. AL Variable Helper is your fellow friend in this situation. It comes with a snippet to declare record variables easily.

By simply typing “Re” and using the Record snippet, you can easily declare a record variable. Alternatively, you can also type “tr” (abbreviation for trecord snippet).

Just type “Re”, take the first value by pressing “TAB. Notice that some words have a light grey background. The words with the light grey background (“v” and “temporary”) indicate that you can jump to these positions by using “TAB”.

Now press Ctrl + Space to get the list of records that you can declare. Start typing and choose your record.

Press “TAB” again. Remove the block “temporary” if not need.

One more time “TAB”. You will jump to the next position of the snippet. Press Ctrl + Space to see what you can do here:

Select full to get the full variable name.

You might notice, that I did something stupid. I declared the variable SalesHeader twice. Please do not be as stupid as I was when creating this example. 😉

Go to Global/Local Variables

This one is pretty easy. Instead of having a separate window for declaring local and global variables like in C/AL, in AL we declare variables in code. This happens in sections marked as “var”.

AL Variable Helper comes with a shortcut to jump to these sections.

If you use the shortcut Ctrl + Shift + P and type al var, you can see the list of available commands provided by the AL Var Helper.

As you can see, the shortcut Ctrl + G is used to jump to the global variables and the shortcut Ctrl + L to jump to the local variables.

Sort Variables

I do not know how you feel about it, but I like to keep my workspaces tidy. AL Var Helper offers a wonderful feature to help you keep your workspace tidy: “Sort Variables”.

What does it do? It sortes the variables declared in your var section – by type and by name. So if you have declared variables like this:

…and use Sort Variables, this will be the result:

How cool is that? The feature does not come with a standard shortcut. This is why I assigned my own shortcut to it (NumPad3).

Fix Keyword Casing

One of the things that changed with al is the casing of keywords. Keywords that “IF”, “BEGIN”, “END” used to be written in capital letters. With AL they are now written in small letters.

You might run into situations, where you want to copy C/AL code to your new AL Project. To avoid having a wild mix between writing your keywords in small letters AND in big letters like in this example…

…you can use the “Fix Casing” feature of AL Variable Helper to help you out in this situation.

Works like a charm.

Have a nice week. 🙂

2 thoughts on “Boost Your Productivity with AL/BC – AL Variable Helper

  1. When I started out programming with AL in Visual Studio Code, everything seemed to take really long. Over the years I have become quite familiar with C/SIDE and C/AL, but developing in AL was a whole new thing.

    I did many things in a stupid and slow way, because I simply did not know a better way. This is how life works I guess. First you do it in a stupid way. Then you hopefully learn from your mistakes. Finally you will find the ways and tricks to perform your tasks in a reasonably smart way.

    After I’ve run myself deeply into this matter, I can now claim that I can program faster with AL than with C/AL. There are so many things you can use to make your life easier than it was with good old C/SIDE and C/AL.

    What This Post Is About: Boost Productivity

    Now you may ask yourself what this post is even about other than me randomly talking about two languages. Well, I thought it might be a good idea to share with you the findings I collected on my journey. During the next weeks and months, I will create a series of blog posts about tricks and tips to boost your productivity when programming with AL and Visual Studio Code. The series will also explain how to use a few especially useful extensions like the CRS Language Extension or AL Variable Helper.

    When I started out, I would have loved to have a collection of useful tips and tricks – even of the seemingly “easy” and “obvious” things. Unfortunately, this did not exist. There are a lot of information out there, but in this rapidly growing field they are spread on various blogs and oftentimes out of date.

    I will give my best to help you avoid taking the same stupid steps I did. My target audience will be the people who are just starting out with AL or do not have a lot of time to experiment with trial and error. Maybe even some experienced developers might find this interesting.

    We will see 🙂

    This is a list of the published posts so far:

    AL Variable Helper
    Todo Tree And TODO Highlight
    CRS Language Extension
    Breadcrumbs
    ID Assigning

Leave a Reply

Your email address will not be published. Required fields are marked *