Marty Zigman

Conversations with Marty Zigman

Certified Administrator • ERP • SuiteCloud

NetSuite SuiteScript 2.0 Search Join and Summary Example

NetSuite Technical

Tags: ,

This article is relevant if you need to understand the NetSuite SuiteScript 2.0 syntax for producing a search with either a join or summary operator.

Background

NetSuite is making investments to grow its SuiteScript 2.0 API.  Thus, to keep up, we old-timers need all the help we can get to learn the new syntax.  The NetSuite Help document is still under development and thus code examples are forthcoming.  At the time of this writing, I had a hard time finding some code examples for searching using the Join and Summary syntax.  So I thought I would offer up an example.

SuiteScript 2.0 Search Example with Join and Summary Operators

//search on employees based on specific roles by joining to role table
var filters = [
   search.createFilter({
        name: 'isinactive',
        operator: search.Operator.IS,
        values: ['F']
   }),
   search.createFilter({
        name: 'internalid',
        join: 'role',
        operator: search.Operator.ANYOF,
        values: JSON.parse(JSON.stringify(roleList))
   })
];

//get the values of the roles in the role table via SuiteScript 2.0
var s = search.create({
  'type':'employee',
  'filters':filters,
  'columns':[
            search.createColumn({'name':'firstname'}),
            search.createColumn({'name':'lastname'}),
            search.createColumn({'name':'internalid', join: 'role'}),
            search.createColumn({'name':'name', join: 'role'})
            // if we wanted to run a summary search, here is the syntax
            //,search.createColumn({'name':'created','summary':search.Summary.MAX})
            ]
}).run();
s = s.getRange(0,1000);

Join A Team of NetSuite Innovators

If you have achieved your NetSuite Certification and wish to be part of the leading team producing NetSuite innovations for the community, let’s have a conversation.

Marty Zigman LinkedIn

Marty Zigman

Holding three official certifications, Marty is widely recognized as a top NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. A former Deloitte & Touche CPA and technology executive with CTO roles, he brings over 35 years of leadership in ERP, CRM, and eCommerce business systems. Contact Marty to engage directly.

BiographyYouTubeLinkedInX (Twitter)

21 thoughts on “NetSuite SuiteScript 2.0 Search Join and Summary Example

  1. The query rendered seems to implicitly execute an INNER JOIN. Is there a way to do a LEFT JOIN as well? For example, if I wanted to get a list of customers along with the name of their parent customer, I would join through the parentcustomer relationship. However, an inner join would omit customers that do not have a parent, so a left join would be preferable.

    Reply
  2. JSON.parse(JSON.stringify(roleList)) — Does this works ? For me it gives error.
    Assume that your rolelist as
    roleList = {“internalid”:”1234″}.

    org.mozilla.javascript.EcmaError: TypeError: Cannot find function _marshal in object [object Object]

    Reply
  3. When I use this code I get a error.

    var roleList = {internalid:14627};
    var x = JSON.parse(JSON.stringify(roleList))

    TypeError: Cannot find function _marshal in object [object Object]

    I asked you this question here becos I was trying to use IN like query in the filter. I have multiple ids to be choose.

    Now the question is how do you find the “join: ‘role'” from “employee” record. I am referring to the current 2017 record browser and not able to find any join in name of role.
    TIA

    Reply
  4. Hi Marty,

    I have a SuiteScript 2.0 that load and search transaction saved search with posting period filter. In my filter I am using ‘anyof’ operator which is not working for ‘postingperiod’ field

    below is sample of my code:

    function getTransactionData(datain)
    {
    try
    {

    var objSearch = search.load(
    {
    id: datain.savedsearchid
    });

    objSearch.filters.push(search.createFilter({ name: “postingperiod”, operator: “ANYOF”, values: [“42”, “43”]}));
    //above filter filters only record with internalid 42
    result = readAllData(objSearch);
    return result;
    }
    catch (ex)
    {
    log.error(“getTransactionData”, ex);
    throw ex;
    }
    }

    Please note above issue is occurring only for saved search and even in saved search only for postingperiod field, if I search other object for example ‘account’ object with internalid filter using ‘anyof’ operator, works fine.

    can you please suggest me some solution for the same.

    Thank you very much.

    Reply
  5. Hi Marty,

    Thank you so much for looking into this.

    Yes, I have tried with quotes also.

    Yes it works for one value, but when I pass multiple value is in an array, anyof filters only for first value of array.

    Yes these are internalids. In my Netsuite account 42 is an internalid of ‘May 2003’ and 43 is an internalid of ‘June 2003’

    Thank you

    Reply
  6. Hi Marty,

    Thanks for article link. I looked into link but in this script ‘anyof’ not been used with ‘postingperiod’ field anywhere. As I mentioned in my query, this issue is only for ‘postingperiod’ field. If I use ‘anyof’ operator with other fields of transaction saved search (for example I create filter for account field using ‘anyof’ operator) it works fine.

    Thanks

    Reply
  7. Hi Marty. Your articles are probably the most informative NetSuite articles I’m aware of, so I’m hoping maybe you can answer a question I haven’t been able to find a definitive answer to. If I set the sort on a single column in a search, and then run that search as a paged search, should it sort the entire dataset by that column? Or should it just sort each page by the specified column?

    For example, I’m running a transaction search that returns a couple thousand records. One of the columns is “balance”, which joins on customer. I want to sort the entire dataset by that column, and then give me the results in pages of 100. But NetSuite seems to only sort each individual page by the customer’s balance, and not the entire dataset. Is what I’m trying to accomplish even possible? Any info would be appreciated.

    Thanks,

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *