How to Use SuiteScript in Browser Console

To test code in the console, we first navigate to a record that supports SuiteScripting. A Sales Order, for example, is a great option to test the console. We also need to enter into edit mode, since this is where Client Scripts primarily find their home. If you try to import SuiteScript modules in view mode, you will likely encounter error messages since client-side scripting is used in edit mode in most cases.

Next, we’ll open our browser console. On a personal note, I prefer to use Chrome, but my team also uses Safari. But either way, just right-click somewhere on the page and find the option to inspect the page. If you don’t see this option, you may need to enable developer features in your browser settings. Once the Developer tools open up, make sure you open to the “Console” tab.

Unlike actual SuiteScripts, we can only import modules using require() instead of define(). You may be accustomed to using define() at the top of your scripts, so this difference might throw you off at first. Using require() will load in any dependencies that are needed, and this is the only way to load in the modules within the console, to my knowledge.

I typically import a module by assigning it to a variable. For example, to import the Record module, I will declare a variable called “record” and assign it to the imported module — “const record = require('N/record').” This allows me to use the record variable easily. There are certainly other more function-based ways to do this, but I’ve found this the easiest method to employ in the console.

Once the currentRecord (or other module) loads, full SuiteScript module functionality is granted. The console is also great for exploring the composition of the NetSuite components in case you’re feeling curious.

Leave a comment

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