We can explore SuiteScript functionality by importing modules to the browser console.
How Can This Help?
Believe it or not, the console is actually among my favorite SuiteScript tools. Few tools are easier, faster, or more helpful than the console. Take, for instance, the need to find a certain field’s value. If you’re unsure whether getText()
or getValue()
will work best, the console is a quick way to find out. If you’re doubting whether a field will return either a number or some stringed value, try it in the console. Not only that, the console also provides support for the latest native JavaScript. So if you need to work out how a certain aspect of your code works, the console can be an excellent tool.
Why Does This Work?
Similar to Client Scripts, importing modules to the console allows us to run SuiteScript code on the client-side (as opposed to server-side). Theoretically, if we can do something through a Client Script, then we can do it in the browser console. But remember, the client-side console will not support server-side modules. We must also remember to test on a NetSuite record that supports both SuiteScripting and Client-side functionality.
How Is This Done?
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.
Conclusion
The console is a very powerful SuiteScript tool. Once you know the basics of how to use it for SuiteScripting, you will be on your way to writing code more efficiently, confidently, and safely. We hope you enjoyed this SuiteScript tutorial. If you would like to see our latest weekly SuiteScript posts, feel free to subscribe to our mailing list!