NetSuite SuiteScript Suitelet List展示搜索数据

1. 前言

NetSuite自带搜索(Saved Search)当有公司间交易,搜索事物(transaction)时,配对的公司间事务处理()字段只能显示该记录internalid,而不是客户容易理解的tranid,或者说叫document number。transaction在saved search中无法再继续关联另一个transaction,所以需要用脚本取出结果,再根据intercotransaction加载出tranid展示出来。


1.JPG
2.JPG
3.JPG
4.png

2. Suitelet编写

/**
 *@NApiVersion 2.x
 *@NScriptType Suitelet
 *@NModuleScope SameAccount
 *@Author kigao
 */
define(['N/ui/serverWidget', 'N/search', 'N/record'],
    function(serverWidget, search, record) {
        function onRequest(context) {
            if (context.request.method === 'GET') {
                var list = serverWidget.createList({
                    title: '公司间交易-订单流转-搜索结果'
                });
                var viewColumn = list.addColumn({
                    id: 'custpage_kian_view',
                    type: serverWidget.FieldType.URL,
                    label: 'VIEW',
                    align: serverWidget.LayoutJustification.RIGHT
                }).setURL({
                    url: 'https://system.netsuite.com/app/accounting/transactions/transaction.nl?'
                });
                viewColumn.addParamToURL({
                    param: 'id',
                    value: 'tranInternalId',
                    dynamic: true
                });
                list.addColumn({
                    id: 'custpage_kian_trans_id',
                    type: serverWidget.FieldType.TEXT,
                    label: 'Transaction Number',
                    align: serverWidget.LayoutJustification.RIGHT
                });
                list.addColumn({
                    id: 'custpage_kian_trans_name',
                    type: serverWidget.FieldType.TEXT,
                    label: 'Transaction Name',
                    align: serverWidget.LayoutJustification.RIGHT
                });
                list.addColumn({
                    id: 'custpage_kian_amount',
                    type: serverWidget.FieldType.TEXT,
                    label: 'Amount',
                    align: serverWidget.LayoutJustification.RIGHT
                });
                var interCompFld = list.addColumn({
                    id: 'custpage_kian_pa_inter_trans',
                    type: serverWidget.FieldType.URL,
                    label: 'Paired Intercompany Transaction',
                    align: serverWidget.LayoutJustification.RIGHT
                }).setURL({
                    url: 'https://system.netsuite.com/app/accounting/transactions/transaction.nl?'
                });
                interCompFld.addParamToURL({
                    param: 'id',
                    value: 'interCompTranInternalId',
                    dynamic: true
                });

                var mySearch = search.load({
                    id: 'customsearch_kian_so_search'
                });
                var rslt = mySearch.run();
                var rows = [];
                rslt.each(function(result) {
                    log.debug('result', result);
                    var row = {};
                    row['custpage_kian_trans_id'] = result.getValue({
                        name: 'tranid'
                    });
                    row['custpage_kian_trans_name'] = result.getValue({
                        name: 'transactionname'
                    });
                    row['custpage_kian_amount'] = result.getValue({
                        name: 'amount'
                    });
                    var intercompanyTranId = result.getValue({
                        name: 'intercotransaction'
                    });
                    row['interCompTranInternalId'] = intercompanyTranId;
                    if (intercompanyTranId) {
                        var fieldLookUp = search.lookupFields({
                            type: 'transaction',
                            id: intercompanyTranId,
                            columns: ['tranid', 'transactionname']
                        });
                        //log.debug('fieldLookUp', fieldLookUp);
                        row['custpage_kian_pa_inter_trans'] = fieldLookUp['transactionname'];
                    } else {
                        row['custpage_kian_pa_inter_trans'] = '';
                    }
                    row['tranInternalId'] = result.id;
                    row['custpage_kian_view'] = 'VIEW';
                    rows.push(row);

                    return true;
                });
                log.debug('rows', rows);
                list.addRows({
                    rows: rows
                })
                context.response.writePage(list);
            } else {
                context.response.write('Received post request... ');
            }
        }

        return {
            onRequest: onRequest
        };
    });

有个问题是展示出来的页面没法分页,还在找解决方案。

3. 展示结果

5.png

4. 加载到菜单中

6.JPG

5. 结语

如有疑问,欢迎留言共同探讨。

你可能感兴趣的:(NetSuite SuiteScript Suitelet List展示搜索数据)