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

Nested Drop Down Lists in NetSuite

Data accuracy should be a top priority in any system-related project and preventing users from entering data that doesn’t make sense will make designing processes and reports much easier. When categorizing objects in many applications, it’s common to use drop down lists for fields such as Category and Sub-Category to help identify objects in reports. By using nested drop down lists, you can ensure that the selected Sub-Categories are relevant to the selected Category. Nested drop down fields can be easily created in NetSuite’¦it’s just not immediately obvious because you’ll need to use custom records rather than custom lists.

Read more

Do you have a Moment?

Working with dates in native javascript can quickly become tedious and cumbersome. You have the standard Date object with a few different methods for constructing that object. Then you have a series of getXXX and setXXX methods that let you work with and manipulate various pieces of that Date object.

But what if you need to do more than that? What if you need to calculate future dates from this object? How do you display your date as a relative time like ‘4 hours ago’ or ‘3 weeks ago’. How do you compare two different Date objects? You could start down a long road toward building your own library of utility methods to answer some of these questions or … Enter moment.js.

Read more

Tasks and Reminders

We all have those things that we need to do every day. They’re just a part of our daily routine that we’ve gotten used to doing day in and day out. But if there’s ever a day when we don’t do them, all kinds of things can happen.

We may be holding up another department’s process or reporting and dashboard data may be out of sync from reality. I recently ran across a routine task that prevents newly shipped cameras from connecting if this task is not performed daily.

Fortunately, NetSuite has some tools to help us remember to do the things that have become routine, tedious and boring. These are Tasks and Reminders.

Read more