NetSuite SuiteScript VS Code Snippets

Published February 26, 2023

In this article, I will show you how to set up and use Visual Code Snippets useful for SuiteScript 2.x. Snippets are a way to add custom IntelliSense auto-complete code blocks to VS Code based on the language defined in the Snippet.

How can I create custom Snippets?

There are a few snippet generators out there. I've found https://snippet-generator.app created by Pawel Grzybek to be pretty easy to use.

How can I add custom Snippets?

VS Code has a straightforward guide on where to add your Snippets, so I'll link to that section. Create your own snippets

SuiteScript Snippets

Here is a link to the Snippets I have created and use daily. NetSuite Javascript Snippets I do need to get in there and start adding some more.
There are three types of Snippets I like to use with SuiteScript.
The first is a full Script Type template. Essentially the idea is to drop in a blank preformatted template for each Script Type (UserEvent, Map/Reduce, Suitelet, etc.).
The second I use is for specific Modules. For example, I have a few for the N/record Module that I often use (record.load(), record.create(), etc.).
Finally, I like using specific methods that sometimes work for multiple Modules. Two examples would be ".getValue()" and ".getSublistValue()" as they work both on N/record and N/currentRecord.

Full Script Type Templates

These blank script templates drop in all of the script's entry points and a few default variables I generally like to use. Some are just copies of the example scripts provided by the NetSuite documentation. This video shows a basic UserEvent script template just by typing "user" then selecting userevent2_1 and hitting Tab so it auto-completes.


In the Javascript Snippet file, I believe I have these Script Templates available.

  • Suitelet
  • UserEvent
  • Map/Reduce
  • Mass Update
  • Restlet
  • Scheduled
  • Client

Module Snippets

I only have a few Module Snippets, to be honest. Likely that is more due to a time constraint on my part than a useability issue. Nevertheless, I plan to make a few updates to the Snippets I have shared publicly.
Here is a quick video showing how I would use the record Module snippets.

Method Snippets

I have only a few of these that I use daily. I initially believed I would use these Snippets more often than I do, but YMMV.
Here is a quick usage of the ".getSublistValue()" method.

Summary

Snippets are incredible, and having the ability to create your own in VS Code is highly resourceful. I have only shown off a few Snippets related to NetSuite, but that is not the limit. You can create any kind of Snippet that would be useful. For example, I have a preferred forEach() loop I use very often.