I am currently working on a JavaScript script that interacts with the Netsuite ERP platform to retrieve data.
Currently, the script is returning data in an array format, specifically product information. While this is functional, I would prefer it to return multiple arrays of arrays to simplify external content handling outside of Netsuite.
The script is querying for 3 products, resulting in an array with 21 keys. Ideally, it should return 3 separate arrays of arrays instead.
I am struggling to determine which loop structure is needed to create these new arrays for better content management.
function loadRecord(request, response)
{
var recType = request.getParameter('recType');
var savedSearchId = request.getParameter('savedSearchId');
var internalid = request.getParameter('internalid');
// Perform the required search.
var filter = [];
if(recType == 'customer' || recType == 'contact' )
{
filter[0] = new nlobjSearchFilter('internalid', null, 'is', internalid);
}
if( recType == 'item')
{
var internal_ids = [25880, 25980, 333];
filter[0] = new nlobjSearchFilter('internalid', null, 'anyOf', internal_ids);
}
if(recType == 'transaction')
{
filter[0] = new nlobjSearchFilter('type',null,'anyOf','SalesOrd');
filter[1] = new nlobjSearchFilter('internalid','customer','is', internalid );
}
var rsResults = nlapiSearchRecord(recType, savedSearchId, filter);
var rsObj = [];
// Unsure about how to restructure the data into nested arrays for more elegant organization...
for (x = 0; x < rsResults.length; x++)
{
var flds = rsResults[x].getAllColumns();
for (i = 0; i < flds.length; i++)
{
var rowObj = {};
rowObj.name = flds[i].getName();
rowObj.label = flds[i].getLabel();
rowObj.val = rsResults[x].getValue(flds[i].getName(), flds[i].getJoin(), flds[i].getSummary());
rowObj.txtval = rsResults[x].getText(flds[i].getName(), flds[i].getJoin(), flds[i].getSummary())
rsObj.push(rowObj);
}
}
response.write(JSON.stringify(rsObj));
}
Any assistance would be greatly appreciated.