How does it help?
Debugging is a crucial part of determining why an OS, application, or program is misbehaving. Even if developers use a similar coding standard, it’s quite likely that a new software program will still have bugs. In many cases, the procedure of debugging a new code/program can take longer than it took to write down the program. Generally, the bugs in software components that have the most use are found and fixed first.
I found the console is an easy and faster way to debug suitescript, for example, I need a field value and I’m not sure which format the value of that field is returned in suitescript. If we are unsure to use getValue() or getText() to get the right format of field value, testing it in the console is the quicker way.
We can explore SuiteScript functionality by importing modules to the browser console when your NetSuite is logged in. It works similarly to Client Script, works on the client-side.
Let’s try this
To test your code in the console, first, we need to log in to your NetSuite account, then navigate to the record that supports SutieScript. As we know, this works similar to client script, only Client Script modules are supported for debugging the code in the console.
A Sales Order or Invoice is the best option for testing the code in the console. If you try to debug in view mode we will likely get error messages, as the Client Script works in edit mode in most of the cases. Now, we’ll open the browser console (chrome or safari). Right-click anywhere on the page and select the option inspect, which then opens the chrome dev tools section.
Now select the console tab.
You can open the console directly using the shortcut commands given above.
Unlike actual SuiteScripts, we can only import modules using require() rather than define(). In standard, You may be using define() at the top of your scripts, so this difference might throw you off at first. Using require() will load any dependencies that are needed, and is that the only way to load the modules within the console to my knowledge.
To load the modules, I typically assign it to a variable. I imported the “CurrentRecord” module using require() and assigned it to a variable so that I can access the Suitescript functions of that module.
In the example, I retrieved some field values of the sales order record. I tested the field “entity” by using getValue() and getText() to check the right format I needed.
We can load other SuiteScript modules in a similar way and we can test and debug the SuiteScript functions quickly.
The console is a very powerful tool, one should know the basics of SuiteScript, it’ll help us to write code efficiently, defect and bug-free.