Create and Run a Joined Search

This sample is a custom module script that creates and runs a joined search. This sample can be used as a custom module or as an individual function within a user event or other server script, so no JSDoc or define statement or return statement or entry point function is needed. But you'll need to load the N/search module for the function to work.

The conversion of this script from SuiteScript 1.0 to SuiteScript 2.1 includes the following:

SuiteScript 1.0 Script

SuiteScript 2.1 Script

                    function myJoinedSearch() {
    // Create a filters array and define search filters for an Item search
    var filters = new Array();

    // filter by a specific customer (121) on the Pricing record
    filters[0] = new nlobjSearchFilter('customer', 'pricing', 'is', '121');

    // filter by a currency type (USA) on the Pricing record 
    filters[1] = new nlobjSearchFilter('currency', 'pricing', 'is', '1');

    // set search return columns for Pricing search
    var columns = new Array();

    // return data from pricelevel and unitprice fields on the Pricing record
    columns[0] = new nlobjSearchColumn('pricelevel', 'pricing');
    columns[1] = new nlobjSearchColumn('unitprice', 'pricing');

    // specify name as a search return column. There is no join set in this field.
    // This is the Name field as it appears on Item records.
    columns[2] = new nlobjSearchColumn('name');

    // execute the Item search, which uses data on the Pricing record as search filters
    var searchresults = nlapiSearchRecord('item', null, filters, columns);
} 

                  
                    /**
 * @NApiVersion 2.1
 */

define(['N/search'], (search) => {
    const myJoinedSearch = () => {
        const filters = [
            search.createFilter({
                name: 'customer',
                join: 'pricing',
                operator: search.Operator.IS,
                values: '121'
            }),
            search.createFilter({
                name: 'currency',
                join: 'pricing',
                operator: search.Operator.IS,
                values: '1'
            })
        ];

        const columns = [
            search.createColumn({
                name: 'pricelevel',
                join: 'pricing'
            }),
            search.createColumn({
                name: 'unitprice',
                join: 'pricing'
            }),
            search.createColumn({
                name: 'name'
            })
        ];

        const searchResults = search.run();

        return searchResults;
    };

    return {
        myJoinedSearch
    };
}); 

                  

General Notices