使用 Search.ResultSet.each 方法

這是最短,最簡單和最常用的方法。不幸的是,它有一個主要限制 - 不能用於超過 4000 個結果(行)的搜尋。

    // Assume that 'N/search' module is included as 'search'
    
    var s = search.create({
        type : search.Type.TRANSACTION,
        columns : ['entity','amount'],
        filters : [  ['mainline', 'is', 'T'],
              'and', ['type', 'is', 'CustInvc'],
              'and', ['status', 'is', 'open']
            ]
    });

    var resultSet = s.run();
    
    // you can use "each" method on searches with up to 4000 results    
    resultSet.each( function(result) {
        
        // you have the result row. use it like this....
        var transId = result.id;
        var entityId = result.getValue('entity'); 
        var entityName = result.getText('entity');
        var amount = result.getValue('amount');
        
        // don't forget to return true, in order to continue the loop
        return true;  

    });