Optimizing SuiteScript Performance

General Scripting Guidelines

  • Save retrieved values on a variable and use again on succeeding calls.
  • Execute a block of code only if it satisfies a condition.
  • Remove redundant operations or actions and lines of code which are no longer used within the script execution.
  • Remove duplicate logic on a script that is already performed by other events.
  • Combine similar scripts/functions whenever possible.
  • Inactivate scripts/deployments that are no longer needed.
  • Use asynchronous processing for user events.
  • Use built-in permissions (by leveraging Run as Role) instead of scripting permissions.
  • To minimize execution logging after your script is tested and released, set your script log level to ERROR or EMERGENCY.
  • Deploy scripts to run as administrator only if necessary to minimize security risk and to eliminate performance overhead.
  • Use execution context filtering to specify how and when a client script or user event script is executed. Execution contexts provide information about how a script is triggered to execute. For example, a script can be triggered in response to an action in the NetSuite application, or an action occurring in another context, such as a web services integration. You can use execution context filtering to ensure that your scripts are triggered only when necessary.

Accessing Records in Scripts

  • If applicable, change the trigger of a script to avoid reloading a record.
  • Avoid saving records multiple times in an After Record Submit event.
  • Avoid loading and submitting a record on a Before Record Submit trigger.
  • Minimize API calls that perform load, search, or save record operations.
  • Use inline editable child custom records whenever your use case calls for batch processing of multiple related/child records during user events on the parent record.

Scripting Searches

  • Optimize search filters and columns. Make your search results faster by:
    • Filtering inactive records.
    • Entering shorter date range criteria.
    • Using faster operators such as starts with/between/within instead of contains/formulas.
    • Removing unnecessary columns.
  • Remove search results columns that are not used by a script. Place any lines that add columns to search results in a comment. Then the returned values are not used by the succeeding script logic.
  • Combine searches of the same record type by using merged filters. Wherever possible, combine searches for the same record into one main search with merged filters. This improves performance by minimizing search instances.

Leave a comment

Your email address will not be published. Required fields are marked *