We are excited to introduce a guest author today - one of our very own Senior Consultants, Karl-Henry Martinsson! Keep an eye on The Vested Group's blog for more posts from Karl in the future or simply visit his personal blog directly at http://blog.texasswede.com/
In an attempt to expand my knowledge to other platforms than Notes and Domino, I have now been working with NetSuite for a number of months. I have mainly been working with the ERP part of the cloud based system.
Since I like my code clean and easy to read (which will make future maintenance easier), I have created a number of functions to encapsulate NetSuite functionality.
The first one I created was to search the database. The search in NetSuite is done by defining the columns (i.e. fields) to return as an array of search column objects. Then an array of search filters is created, and finally the search function is called, specifying what record type to search and passing the two arrays to it as well. This is a lot of code, and with several searching in a script it can be very repetitive, not to mention hard to read.
Here is an example of a traditional NetSuite search:
Using my function, the code wold be simplified to this:
The function also support saved searches. Simply add the following line:
There is a limitation in SuiteScript so that a maximum of 1000 records can be returned by a normal search. There is a trick to bypass this, but it requires some extra coding. So I thought why not add this into the function as default? So I did.
Below is the code for the search function. I usually put it in a separate file and reference it as a library in the scripts where I want to use it. This first version does not support more advanced functionality like formulas in the filters, but for most searches this function will be usable.