Saved search result in a given format

Create a suitelet script to provide search result in the format.

/**
 * @NApiVersion 2.1
 * @NScriptType Suitelet
 */
/*******************************************************************
 *   Suitelet Script returns search result for klipfolio
 ****************************************************************
 *
 * Date: 11/02/2022
 *
 * Author:  Jobin and Jismi IT Services LLP
 *
 * REVISION HISTORY
 *
 * Revision
 *
 * Description: Search returns the result in a given format for klipfolio
 *
 ***************************************************************/
define([ 'N/search'],
    ( search) => {
        /**
         *  @param function to Create search result in a given format
         *  @param returns search result
         */
        const onRequest = (scriptContext) => {
            try {
                var response = scriptContext.response;
                //load the search with id to obtain the required result
                var searcResult=search.load({
                    id:'customsearchomp_uk_open_cases_3'
                });
                //Run the search result
                var searchResultCount = searcResult.runPaged().count;
                log.debug("searchResultCount",searchResultCount)
                var results = searcResult.run().getRange(0,1000);
                //stringify the result and write the the result
                var newResult= response.writeLine(JSON.stringify(results));

            }catch (e) {
                log.error('on_request', e.message);
                log.debug('on_request', e.message);
            }
        }
        return {onRequest}
    });

Leave a comment

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