Suppose you read my first Netsuite Search with SuiteScript 2.0 tutorial but you want a BIT more information? First, if you haven't, read the first tutorial.
Then read this...
/**
*@NApiVersion 2.x
*@NScriptType UserEventScript
*/
define(['N/search', 'N/log'],
function(search, log) {
return {beforeLoad: beforeLoad};
function beforeLoad(context){
var srch = search.create({type: 'itemfulfillment', filters: [], columns:[]};
var srchResults = srch.run();
srchResults.each(function(result){
log.debug('Result', result.id);
});
}
}
);
In the search.create, there's filters and columns. For filters, they are arrays of search.createFilter() objects that look like this:
var filters = [search.createFilter({name: 'fieldtosearch', operator: 'anyof', values: ['value1', 'value2', 'value3']})];
This will give you a single object in the needed array. You can obviously add more as needed.
For columns array, you can use it a few ways. It can be an array of strings like this:
var columns = ['field1', 'field2', 'recordid.field3'];
or:
var columns = [{name: 'field1'}, {name: 'field2'}, {name: 'field3', join: 'recordid'}];
Notice the two are very similar but one has a join as part of the object and the other is simply a string with a dot to denote the joined record? It can get pretty complete and I would recommend playing around in the Netsuite Script Debugger to test various ways to create your searches within SuiteScript 2.*.
That's a more advanced usage of a search in Suitescript 2.0. It's a little more complex than Suitescript 1.0 but it offers a much more modular and flexible design pattern.
I hope this helps any noobs learning Netsuite's SuiteScript. I know me being self-taught, these types of articles were a Godsend to me to help explain code more than a generic API document of functions and properties.
Top comments (0)