DEV Community

Cover image for Netsuite Searching with SuiteScript 2.0 "Snyder" cut
Erick
Erick

Posted on

Netsuite Searching with SuiteScript 2.0 "Snyder" cut

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);
            });
        }
    }
);
Enter fullscreen mode Exit fullscreen mode

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']})];
Enter fullscreen mode Exit fullscreen mode

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'];
Enter fullscreen mode Exit fullscreen mode

or:

var columns = [{name: 'field1'}, {name: 'field2'}, {name: 'field3', join: 'recordid'}];
Enter fullscreen mode Exit fullscreen mode

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.

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay