SuiteScript with a Safety Net

Ready to save your customer record? Don’t forget to wrap your call in a try/catch block, right? You need to handle the case when the save is successful…AND…you need to handle the case when the save is unsuccessful.

  • What if your user forgot to enter some data?
  • What if the value they entered for the email address on your custom form is incorrect?
  • What if … any of 1000 other things go wrong when you try to save that record.

Read more

Rules for a Knight

The following are excerpts from Rules for a Knight by Ethan Hawke.

Solitude

Create time alone with yourself. When seeking the wisdom and clarity of your own mind, silence is a helpful tool. The voice of our spirit is gentle and cannot be heard when it has to compete with others. Just as it is impossible to see your reflection in troubled water, so too is it with the soul. In silence, we can sense eternity sleeping inside us.

Read more

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