Don’t Miss it: Top Strategies for Driving Diversity

days / hours / minutes / seconds

Register Here »
NetSuite logo
NETSUITE RESOURCES
workplace by meta logo
FUTURE
OF WORK WORKPLACE BY META
University icon
CUSTOMER EDUCATION blog
Atlassian Logo
Adoption blog
How-to
October 5, 2023
|
9 min
reading time

SuiteScript 2.0: Suitelet Sample Code for Displaying Transactions in a List

Share this article

Do you want to show a custom list in your NetSuite account, but don’t see a way to do it with Saved Searches? If this has happened to you, you’re not alone.

For anyone struggling with the limitations of Saved Searches in NetSuite, if you want to create customized lists in NetSuite SuiteScript, you can achieve this through a type of SuiteScript called a “Suitelet”.

With Suitelets, you can display a simple list of your desired values with more flexibility. For example, if you're looking to show transactions in a list, there are several things you can do in a suitelet that Saved Searches does not support. These include:

  • Combining two searches and displaying them in a single list.
  • Choose whether to have simple or complex calculations to adjust your data.

With Suitelets, you can have more flexibility in controlling the user interface, making getting the exact display you're looking for easier.

To help you get started, we've created a sample code to show you how to display transactions in a list. Copy the code below into a Suitelet in SuiteScript 2.0 to see how it looks in your NetSuite account:



/**
 *@NApiVersion 2.x
 *@NModuleScope Public
 *@NScriptType Suitelet
 */
define(['N/log', 'N/ui/serverWidget', 'N/record', 'N/search'],
    function(log, serverWidget, record, search) {

        function onRequest(context) {

            var objClass = {};

            if (context.request.method === 'GET') {

                var list = serverWidget.createList({
                    title : 'LEACC - serverWidget.List'
                });
                list.addColumn({
                    id : 'internalid',
                    type : serverWidget.FieldType.TEXT,
                    label : 'ID',
                    align : serverWidget.LayoutJustification.RIGHT
                });

                list.addColumn({
                    id : 'tranid',
                    type : serverWidget.FieldType.TEXT,
                    label : 'DOCUMENT NO.',
                    align : serverWidget.LayoutJustification.RIGHT
                });
                list.addColumn({
                    id : 'trandate',
                    type : serverWidget.FieldType.TEXT,
                    label : 'DATE',
                    align : serverWidget.LayoutJustification.RIGHT
                });

                list.addColumn({
                    id : 'currency',
                    type : serverWidget.FieldType.TEXT,
                    label : 'CURRENCY',
                    align : serverWidget.LayoutJustification.RIGHT
                });

                var results  = [];

                //Create Search
                var objFilter = [{
                    name: 'mainline',
                    operator: 'is',
                    values: ['T']
                }];
                var objColumns = [{
                    name: 'internalid'
                }, {
                    name: 'tranid'
                }, {
                    name: 'trandate'
                }, {
                    name: 'currency'
                }];

                var searchObj = search.create({
                    type: search.Type.SALES_ORDER,
                    columns: objColumns,
                    filters: objFilter
                });

                searchObj.run().each(function(result) {
                    var res = {};
                    res['internalid'] = result.getValue({
                        name: 'internalid'
                    });
                    res['tranid'] = result.getValue({
                        name: 'tranid'
                    });
                    res['trandate'] = result.getValue({
                        name: 'trandate'
                    });

                    res['currency'] = result.getText({
                        name: 'currency'
                    });

                    results.push(res);
                    return true;
                });

                log.debug('results',results);
                list.addRows({
                    rows : results
                });

                context.response.writePage(list);

            }
        }

        return {
            onRequest: onRequest
        };
    });

Want More Help With SuiteScript 2.0?

With ServiceRocket, you’ll get certainty, expertise and success built into your NetSuite implementation, configuration and custom development. When you work with us, you get access to NetSuite-trained Certified Developers with over 400+ NetSuite scripts and 50+ Suitelet workflows combined. Rest assured that ServiceRocket will help you find success and provide you with the opportunities you need to transform your business.

Do you have NetSuite license management, implementation, administration, support or custom development needs? We’ve got your back! Contact our NetSuite Certified Experts today.

Ensure the highest return on your NetSuite investment with our custom development or administrative services.

Learn MoreServiceRocket Backed - We've got your back badge
x close icon

SUBSCRIBE TO 
OUR NEWSLETTER

Stay informed, subscribe for updates and exclusive content today!
// Code snippet style /*SoMe buttons*/ <-- Facebook Share Button Code --> <-- Facebook Share Button Code --> <-- Twitter Share Button Code --> <-- Twitter Share Button Code --> <-- Linkedin Share Button Code --> <-- Linkedin Share Button Code -->