Best Practices For Using Searches in SuiteScript

Best Practices For Using Searches in SuiteScript

Category : Uncategorized

  1. Avoid the practice of using searches per individual line item :

Using searches per individual line item reduces the efficiency of the script. Instead, build an array to hold the list of item records and use that as the filter. This way one search can be executed for all the records instead of performing individual searches per line.

  1. Avoid loading the record of each search result :

When a search is performed, avoid the API calls for load record or Lookup field for loading the record to retrieve data. Because of unnecessary API I/O calls, this method is considered as inefficient. The best way to overcome this situation is to add the desired columns to the search and use getValue.

  1. Consolidate multiple searches into one search with a broader condition : 

Instead of running the search repeatedly if the script runs several searches for the same record, modify the returned search result in each of the distinct cases.

  1. Create search instead of loading a search: 

Even though the search is independent of the Governance limit, it is better to create a search instead of loading one because the user might accidentally modify the search criteria or even delete one. In this case, while a script tries to load these searches, it returns an error and stops the execution.