web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Jesús Almaraz blog / VSCode+Snippets=Patterns (v...

VSCode+Snippets=Patterns (very basic)

Jalmaraz Profile Picture Jalmaraz 669

Context

We can define snippets as regions of reusable code. Snippets have two exciting sides: use other people snippets and create your own snippets. The potential and simplicity of snippets make them a great tool.

The subject of this post is show an interesting thing: how to create a pattern snippet and use it later. If you want to review NAV patterns visit this link: https://community.dynamics.com/nav/w/designpatterns

Warning: I am an absolute beginner in VSCode and far away from doing something strong with this tool, advanced users will be bored about this post. I use them in very basic mode and there are a lot of more features to use: add placeholders, regular expressions and later package and publish snippet.

Create the pattern

In the example we are going to create part of this pattern:

https://community.dynamics.com/nav/w/designpatterns/125.journal-template-batch-line

We only will create the snippet for Journal Batch table.

Open VSCode and go to File/Preferences/User Snippets:

6443.VsCode1.png

Choose AL language and the editor open the "al.json" file. Then you put there the snippet code:

4604.VsCode2.png

Some comments about this snippet:

  • We must write the content of the snippet code in body section.  Each line must be delimited by double quote, or I think so, and ended by colon.
  • Json is (very) case sensitive.
  • The scape character is "\". You need it for write the double quote within the line.
  • The character "$" at the beginning of a word ($Master) means a variable or tabstop. We will see bellow that this is very interesting. 

Using pattern.

When editing VSCode, you can type the snippet prefix:

2844.VsCode3.png

Then it carry all this code:

0474.VsCode4.png

Notice, that if you select and replace text "Master" by "Palet", automatically replace it in all the "Master" instances.

Comments

*This post is locked for comments