NetSuite saved searches allow you to create reusable search definitions with many advanced search filters/results display options. Although saved searches must be created in the UI, you can pass the internal ID of the saved search to SuiteScript and re-execute the search on a regular basis. This allows you to keep the searches up-to-date for all who might need to access the results.
To re-execute an existing saved search, you will use
nlapiSearchRecord(type, id, filters, columns) .
For general information on NetSuite saved searches, see
Using Saved Searches in the NetSuite Help Center.
When using the nlapiSearchRecord(...) function to execute an existing saved search, note the following:
|
Only saved searches on record types currently supported by SuiteScript can be executed. For a list of records that support SuiteScript, see
SuiteScript Supported Records in the NetSuite Help Center.
|
|
Tip : You may want to include the script administrator in an email notification for any time a saved search included in the script is updated. Email notifications can be defined on the Alerts tab of the saved search definition.
|
On a Script record page, if you define a saved search as a List/Record script parameter, only saved searches that are public will appear in the List/Record parameter dropdown field. For information on script parameters, see
Creating Script Parameters Overview in the NetSuite Help Center.
|
|
In
nlapiSearchRecord(type, id, filters, columns) , the value of
id can be the ID that appears in the
Internal ID column on the Saved Searches list page (see figure below). Or it can be the value that appears in the
ID column.
|
If you have created a custom scriptId for your saved search, this will appear in the
ID column.
Note: To access the Saved Searches list page, go to Lists > Search > Saved Searches.
In the following code, a Customer saved search is executed. The ID customsarch57 references a specific saved search.
function executeSavedSearch() { // specify the record type and the saved search ID var searchresults = nlapiSearchRecord('customer', customsearch57, null, null); for ( var i = 0; searchresults != null && i < searchresults.length; i++ ) { var searchresult = searchresults[ i ]; } }