0
votes

I was tasked to create a custom search that displays results from the tax code records. I managed to create one but now I have to convert it into SuiteScript 1.0 and I am still not familiar with it. Where should I start first? Here is my code:

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 : 'Custom Tax Search'
            });
            list.addColumn({
                id : 'internalid',
                type : serverWidget.FieldType.TEXT,
                label : 'Internal ID',
                align : serverWidget.LayoutJustification.LEFT
            });
            list.addColumn({
                id : 'itemid',
                type : serverWidget.FieldType.TEXT,
                label : 'Item ID',
                align : serverWidget.LayoutJustification.LEFT
            });

            list.addColumn({
                id : 'rate',
                type : serverWidget.FieldType.TEXT,
                label : 'Rate',
                align : serverWidget.LayoutJustification.LEFT
            });

            list.addColumn({
                id : 'taxtype',
                type : serverWidget.FieldType.TEXT,
                label : 'Tax Type',
                align : serverWidget.LayoutJustification.LEFT
            });



            var results  = [];

            //Create Search
            var objColumns = [{
                name: 'internalid'
            }, {
                name: 'itemid'
            }, {
                name: 'rate'
            }, {
                name: 'taxtype'
            }];

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

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

                res['rate'] = result.getValue({
                    name: 'rate'
                });

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

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

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

            context.response.writePage(list);

        }
    }

    return {
        onRequest: onRequest
    };
}); 
1
why convert? If it works it works - bknights
SuiteScript 1.0 is essentially deprecated. Every year, at SuiteWorld, they repeat that you should not be building in 1.0. So, you should also definitely not downgrade a 2.0 script to 1.0. ;) - w3bguy
Sadly my co-workers from the overseas branch uses suitescript 1.0 and they wont bother learning 2.0 for they are busier than here. I asked my boss too and he said the same thing. As a newbie I should adapt for their conditions though. - Aeol Cross
Tell your manager that is a really bad idea. 2.0 is not just a matter of standards but of scalability, if you need help with this just send me an email. - felipechang

1 Answers

1
votes

NetSuite has a complete list of functions from SuiteScript 1.0 to 2.0 migration, you can refer that and work your around it.

nlapi: SuiteScript 1.0 to SuiteScript 2.0 API Map

nlobj: SuiteScript 1.0 to SuiteScript 2.0 API Map