SuiteScript 2.0 Joined Search Example

Seriously, I don’t know why this was so difficult, but I could not find a full working example of an ad hoc search written in SuiteScript 2.0 that included a join. Let me give a quick shout-out to Marty Zigman. Thanks for getting me 90% of the way there!

Here’s Marty’s example:

I’m a bit stupified by the .run().getRange(0,1000). I was trying to use .run().each() and could not get it to work. I’m not a fan of the for-loop in this case. Whatever!… This works!

Here’s the example. This script lists files in a folder that begin with text of your choosing.

Code Example

And here’s the code so that you can easily copy it.

*@NApiVersion 2.x
*@NScriptType ScheduledScript
define([‘N/search’, ‘N/log’],
    function (search, log) {
        function execute(context) {
            var mySearch = search.create({
                type: search.Type.FOLDER,
                columns: [
                        name: ‘internalid’,
                        join: ‘file’
                        name: ‘name’,
                        join: ‘file’
                filters: [
                            name: ‘name’,
                            operator: search.Operator.IS,
                            values: [‘Your folder name here’]
                            name: ‘name’,
                            join: ‘file’,
                            operator: search.Operator.STARTSWITH,
                            values: [‘Your file name here’]
            var result =, 1000);
            var ids = new Array();
            var names = new Array();
            for (var i = 0; i < result.length; i++) {
                ids.push(result[i].getValue({ name: ‘internalid’, join: ‘file’ }));
                names.push(result[i].getValue({ name: ‘name’, join: ‘file’ }));
            log.debug(‘ids’, ids.join(‘,’));
            log.debug(‘names’, names.join(‘,’));
            return true;
        return {
            execute: execute

2 thoughts on “SuiteScript 2.0 Joined Search Example

    1. var myPages = mySearch.runPaged({ pageSize: 1000 });

      for (var i = 0; i < myPages.pageRanges.length; i++) {
      var myPage = myPages.fetch({ index: i });
      function (result) {
      var internalid = result.getValue('internalid');


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s