Search Issues and Best Practices for SOAP Web Services and SuiteScript
You may encounter issues when a SOAP web services or SuiteScript search executed in NetSuite returns multiple pages of results. These issues occur because records can be created, deleted, or updated as you page through the search results. You can avoid the issues described here by following the best practices.
Potential Issues for SOAP Web Services and SuiteScript Searches
Consider the following possible issues when you execute a search in SOAP web services or SuiteScript that returns a large data set.
-
If a record that originally fit the search criteria is updated and no longer fits the criteria, it is skipped by the search. In this case, some records that were originally included in the search results may not be returned, and the total number of returned records may be smaller than the original total number of results.
-
If new records are created that fit the search criteria, they are also returned. The total number of returned records may be higher after you page through the results than the original total number of results, and duplicate results may be returned.
-
Results may be missing. For example, if a record from the first results page is updated and it no longer fits the criteria, another record now fits into page one. However, because earlier pages are skipped when going through subsequent pages of search results, this record is not returned.
-
In SOAP web services, a greater or smaller number of records may be returned after you page through the search results than the number of records that originally fit the search criteria.
-
Page two and the subsequent pages of the results set may contain fewer records than the specified page size.
-
If new records of the same type, matching the search criteria, are created between a search request and a searchMoreWithId request, it can cause position changes in the results and can move records on or even out of search pages. This causes missing or duplicate records on pages.
Best Practices for Searches in SOAP Web Services and SuiteScript
To avoid the issues associated with paging through search results, and for more reliable search results, consider the following best practices.
-
Avoid using loosely defined search criteria that return a large data set. If a large data set is returned and you must go through the results page by page, records may be missing or duplicated, because the data may keep changing as you go through the pages of search results. You can use Advanced Search to help avoid this issue.
-
Make your search criteria as specific as possible. With more specific criteria, the result set is smaller and there is less chance that records fitting the search criteria are created or updated as you go through the pages of the result set.
-
If your search results fit into one page, you can avoid the issues that may occur when you page through the result set.
-
Similarly, if you use more specific search criteria, there is less chance that records are updated in a way that they no longer fit the criteria. You can avoid the issue of records missing from the result set.
-
Using a within lastModifedDate filter is the best solution to ensure new or updated records will not fit the search criteria or to ensure that no new records are added or updated during your search.
-
In SuiteScript 2.0, as an alternative to using the N/search module, you can use the searchTask object members and searchTaskStatus object members of the N/task Module when you search for large data sets. Note that searchTask is an asynchronous search.
-
By creating a hybrid integration that uses SOAP web services and RESTlets, you can also use the N/task module as an alternative to SOAP web services search.
-
In SOAP web services searches, use Advanced Searches, specify a Sort by column, and reference existing saved searches when possible. This way you avoid performance issues like slow SQL and timeout. For more information, see Advanced Searches in SOAP Web Services.
-
If your search contains a search join, you can lower the occurrence of issues with duplicate results by setting two Sort By columns. First sort the results by the internal ID (or another unique field) of the primary table, then by the internal ID (or another unique field) of the second table.
Related Topics
- search
- Basic Searches in SOAP Web Services
- Joined Searches in SOAP Web Services
- Advanced Searches in SOAP Web Services
- Joining Through Custom Fields
- Setting Valid Search Values
- Setting the anyof, mine, or myteam Filtering Values
- Searching by lastModifiedDate
- Understanding Sorting in Advanced Search
- Search-Related Sample Code
- Searching for a Multi-select Custom Field