SuiteScript 2.0: Suitelet Sample for Displaying Transactions in a List

Customized lists – how do you achieve it through NetSuite SuiteScript?

Do you want to show a custom list in your NetSuite account, however you are running into the limitation of Saved Searches?

This can be achieved through a type of SuiteScript called “Suitelet”.

With Suitelets, you can display a simple list of your desired values with more flexibility. Here are some of the things you can do in a suitelet list that are not supported in Saved Searches.

  • You can choose to combine two searches and display it a single list.
  • You can choose to have simple to complex calculations to do some adjustments on your data.
  • You can have more flexibility in controlling the user interface.

Below is a sample code that you can use to see how it looks like.

/**
 *@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 SuiteScript 2.0 code examples? Go to this link!

LEACC Consulting is a team of NetSuite Certified Developers with IT experience solely dedicated to NetSuite technologies for eight years. We are experts in both SuiteScript 2.0 and SuiteScript 1.0. Our team has worked with 400+ NetSuite scripts and workflows combined. If you have some consulting or development needs, contact us by filling out this form or by commenting below.

Do you have NetSuite Development needs? Do you need help with creating suitelets? Our team has created more than 50 suitelets in the past. Click on the link below and let’s have a chat about your project requirements!

Contact us for your NetSuite needs!

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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