Sunday, December 23, 2018

Group search results in a SuiteScript search

Searching transactions will return duplicate entries per record depending on the item lines added. So the search will return only one entry per transaction record, the mainline filter should be added or group the results. Below is sample script that would group the results by transaction id (tranid).

var filters = new Array();
filters[0] = new nlobjSearchFilter( 'custbody5', null, 'is', 'T');

// Define search columns
var columns = new Array();
columns[0] = new nlobjSearchColumn( 'tranid',null,'group' );

var searchresults = nlapiSearchRecord( 'journalentry', null, filters, columns );


for ( var i = 0; searchresults != null && i < searchresults.length; i++ )
{
    var journalId = searchresults[ i ].getValue('tranid',null,'group');
    nlapiLogExecution('DEBUG','Journal ID', journalId);
}

No comments:

Post a Comment