SuiteScript 2.0 has many interesting new features that make it a desirable starting point for NetSuite developers. One of the more useful features is custom modules. Custom modules allow you to group common functions into reusable libraries. These functions can be common helper functions like those used to parse dates or convert numbers. Custom modules can also be used to import third party API’s. All the while keeping common functions separated from the key business logic. 

I didn’t really expect to get as much mileage as I did out of custom modules. I have collected and organized my common functions into libraries which I find myself reaching for on every project because of the ease of use and reliability of the code contained therein. So here are my top 3 tools that I cannot live without. 

The first extends NetSuite’s format module by adding custom functions. No magic to the functions, in some cases the functions are taken directly from NetSuites help on the format function. Thank You NetSuite. In others they are common functions all JavaScript developers use. 

parseAndFormatDateString(initialFormattedDateString – returns a date from a string.
dateToString – returns a string format of a date
parseIntOrZero – old reliable return integer or zero if its null or NaN.
parseFloatOrZero – same function as parseInt for floats.
getNSCurrentDate – returns the current date formatted.
roundVal – function used to do rounding. 

My 2nd library extends the record module. SuiteScript 2.0 uses JSON to pass parameters to the get and set field value functions. In some cases you can pass the parameters without JSON and in others you cannot. My functions allow you to pass the parameters without JSON formatting and it returns formatted JSON. This is key when you copy code written for SuiteScript 1.0. 

sfv – set field value.
gfv – get field value.
scsfv – set current sublist field value.
gcsfv – get current sublist field value.
gsfv – get sublist field value.

Since the validation on these parameters is limited this helps with syntax. 

The final of my top 3 extends the log module by creating a custom error handler and other debugging functions. 

The error handler is used to format errors. Since there are times when I want the error to be thrown immediately and others I want it to bubble up to the next catch statement I put a parameter in to throw immediately or wait and let the caller handle the error. 

The 2nd function in this library I call biglog. This function properly handles strings with lengths greater than 4K by breaking the string down into 4K chunks. This is very useful when you have long strings that are getting truncated in the log.debug statement. 

Custom modules are some of the tools of the trade. These libraries are like the tools a plumber would use to fix a sink. Imagine a plumber building a wrench to fix a sink. Libraries are tools of the trade and we are expected to have a toolbox with all the tools in it. Happy Hacking!! 

Wait! Before You GoWould you like to talk to a business software expert to answer your questions?

When you schedule a free consultation with MIBAR, you will experience a one-on-one conversation with a business technology expert who is passionate about understanding your unique needs or issues. Schedule a free consultation today at the link below or give us a call at (212) 869-9300.

Learn More