SuiteScript Function Naming

Over time, everyone builds their own style of programming. A lot of that style is defined by your past experience, where and how you learn a particular concept, the context in which the code is being written and your goals when writing that code. There are many styles of programming and I would not consider any of them to be right or wrong because there are pros and cons to each way of getting the job done.

When writing scripts for NetSuite there are a few things to keep in mind. What do I name my function? When is the script going to execute? What is the script going to do? Let’s talk about naming our functions.
Read more

map() your NetSuite Search Results

Almost every script that I write for NetSuite performs a search for some kind of data. You can accomplish this easily with SuiteScript by using either nlapiLoadSearch(), which will run an existing saved search and return the results, or nlapiSearchRecord(), which is used to build your saved search in code.

I prefer the latter option since the script does not have the external dependency on the saved search. If anyone were to change or delete that search, the script may no longer perform as expected. Also, by defining the search within the script itself the search logic can be stored in your source code repository.

Both of these functions return an array of nlobjSearchResult. but these objects can be cumbersome to work with and frequently calling getValue() or getText() can introduce a bit of noise into your code making it more difficult to read. I prefer to take these results and convert them into an an array of standard Javascript objects. This can make your search results easier to work with. Fortunately, the Javascript map() function works perfectly for this scenario.  The map() function executes a callback function for each element in an array and creates a new array from the results of the callback function.

Read more