Automatically Create Procedure Stub / AL Navigator

Automatically Create Procedure Stub / AL Navigator

Last week I added a new feature to my Visual Studio Code Extension AL Navigator that makes it possible to create a procedure stub in AL. If you have not read my post about that extension yet, you can checkout this link. Here is the link to the newest extension on the VS Code Marketplace.

What Does It Do?

So what does this new feature do? It implements a functionality that I was strongly missing – detecting a procedure call and automatically creating the stub for it.

When And How To Use It?

Sometimes you will have situations, where you are programming something in a trigger or in a function. You already know, that you will split your code up in different functions because otherwise your code will be messy and hard to read.

You already write your procedure call and are then prompted with an error that the name “FunctionCall” does not exist in the current context.

I have to admit. When it comes to things like this, I am lazy. I do not want to write the stupid procedure stub if it is already clear what will be in there. We have 3 local variables (a, b, customer) and a procedure name “ShowExtensionExample”. This is where the extension comes into play. It provides you the possibility “Add Procedure Stub” with a quick fix lamp. This will automatically create the procedure stub in AL for you. If you prefer the keyboard, you can also just use the shortcut “CTRL” + “.”.

The procedure stub is now automatically created. It detected the used variables and added a TODO. This is especially cool if you use Gruntfuggly’s Todo Tree Extension.

A few final notes on this extension, what it is able to do now and what it will soon be able to do.

What It Can Do

  • Detect a not existing procedure call in the current file/object
  • Create a not existing procedure in the current file/object
  • Create a not existing procedure in a another object/file. If we take our example and want to call a not existing procedure in another codeunit, the stub creation is also possible. Something like this:
    • OtherCodeunit.ChangeMyIntegerValue(IntegerValue);
  • Detect local variables and add them to the stub
  • Detect global variables and add them into the stub
  • Detect the variable type of a return value and create procedure stub properly, something like this:
    LastEntryNo := GetLastEntryNo();
  • Write a TODO in the created stub

Hope some of you enjoy this new extension feature. Have a nice week!

2 thoughts on “Automatically Create Procedure Stub / AL Navigator

  1. Features

    My AL Navigator extension for Visual Studio Code enables you to automatically create variables in AL and navigate through .al files with awesome shortcuts.

    AL Navigator – Create Variables

    AL Navigator provides a CodeAction for the AL compiler error 118 “The name does not exist in the current context“. This CodeAction enables you to automatically create a local or global variable by using the names of standard objects as well as names of your local workspace files. The extension will automatically detect the object type and name and create a variable for it. If no object type and name can be found however, the variable will be created without a type. In other words, it is smart!

    Use the Quick Fix lamp (Ctrl + .) to automatically add variables.

    Finally, here you can see an example:

    AL Navigator – Shortcuts

    I love to use shortcuts. Whenever possible, I would prefer them over the mouse. Thus, this extension comes with a few very useful shortcuts, from which the most useful ones in my opinion are these:

    AL Navigator: Next DataItem: Jumps to the next data item in your report .al file
    AL Navigator: Last local var line: Jumps to the last line of your local var section (a nice addition to the AL Variable Helper by Rasmus Aaen)
    AL Navigator: Last global var line: Jumps to the last line of your global var section (a nice addition to the AL Variable Helper as well)

    Here is an overview of the complete shortcut list:

    Ctrl + o + m: jump to the OnModifyTrigger
    Ctrl + o + i: jump to the OnInsertTrigger
    Ctrl + o + d: jump to the OnDeleteTrigger
    Ctrl + Alt + l: jump to last line of local var section (fast way to declare new variables)
    Ctrl + Alt + g: jump to the last line of global var section (fast way to declare new variables)
    Ctrl + Alt + k: jump to the keys section in your .al file
    Ctrl + Alt + a: jump to next action in a page .al file
    Ctrl + Alt + t: jump through all triggers in your .al file
    Ctrl + Alt + d: jump through data items in your .al report file
    Ctrl + Alt + j: jump through OnAfterGetRecord triggers in your .al file

    AL Navigator – Create Procedure Stub

    A few months ago, I added a feature to automatically create procedure stubs. You can read more information about it here. Last week I removed this feature, after it was better implemented in the extension AL CodeActions.

    AL Navigator – Download

    You can download the extension from Visual Studio Marketplace or via Visual Studio Code. If you are interested in the source code, you can find the github project here.

    Have a nice week!

  2. Sometimes work can be frustrating. I sometimes get frustrated when I find out that there seems to be no quick way of doing things. When you develop reports with Visual Studio Code and AL, you often want to add columns in the dataset for a data item. Sometimes you also want to add code in the triggers. I noticed that there is no shortcut to jump through the data items of an .al report file. My new extension AL Navigator changes that!

    I am talking about these dataitems:

    Sure – there is the extension “AZ AL Dev Tools/AL Code Outline”. I could use the AL Outline to do that, but for complex reports that takes too much time.

    I am one of those guys who mostly prefers keyboard over mouse. So I decided to write a small VS Code extension with really simple, but for me quite helpful features:

    DataItem Jumping: Use the shortcut Ctrl + Alt + d to jump through data items in your .al report file

    OnAfterGetRecord Jumping: Use the shortcut Ctrl + Alt + g to jump through OnAfterGetRecord triggers in your .al file

    Trigger Jumping: Use the shortcut Ctrl + Alt + t to jump through all triggers in your .al file

    Keys Jumping: Use the shortcut Ctrl + Alt + k to jump to the keys section in your .al table file

    Update: AL Navigator now also has a feature do automatically create procedure stubs for you. Read this post for more information on this.

    This is the first VS Code extension I developed, so I cannot guarantee that it is completely flawless. I hope, that this will help some of you.

    Currently I am already working on new features for this extension. As soon as they are completed, I will write a new blog post.

    I am always open for suggestions!

    AL Navigator on VS Code Marketplace

    AL Navigator GitHub

    Have a nice week!

Mentions

  • Waldemar Brakowski
  • Waldemar Brakowski

Leave a Reply

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

%d bloggers like this: