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

Leave a Reply

%d bloggers like this: