They are many ways to utilize Saved Searches in NetSuite using SuiteScript, either by:
-Creating the Saved Search and programmatically add the filter and add and retrieve the columns
- Creating the Saved Search using the NetSuite UI and then using Suite Script to retrieve the results and columns.
The aim of this article is to show you how to retrieve column result values from an existing saved search.
Sample Code
var searchResults = nlapiSearchRecord ( recordTypeInternalID, savedSearchInternalID );
//nlapiSearchRecord(type, id, filters, columns) or nlapiSearchRecord(type, id) - Returns nlobjSearchResult objects corresponding to the searched records.
for ( var i in searchResults ){
var results = searchResults[i];
var columns = results.getAllColumns();
//getAllColumns() is a method within the nlobjSearchResult Class
// getAllColumns() - Returns an array of nlobjSearchColumn objects containing all the columns returned in a specified search
for(var n in columns){
var columnValue = results.getValue(columns[n]);
var columnText = results.getText(columns[n]);
}
}
No comments:
Post a Comment