top of page
Post: Blog2_Post

Blog Article

When to use 'require()' vs 'define()' in SuiteScripts

Updated: Feb 3

Written by: Jude Apron

In SuiteScripts, both require() and define() are used to load modules, but they are used in different contexts.

define() is used when defining a module or script file. It's commonly used at the top of a script file to load dependencies. It's also the function you'll use for SuiteScript entry points (like User Event scripts, Scheduled scripts, etc.).

On the other hand, require() is used to dynamically load modules. It's most often used within a function or a block of code, rather than at the top of a file. This approach can help with performance because the module is only loaded when require() is called, not when the script file is initially loaded.

You should use define() for SuiteScript entry points and `require()` in most other cases. But remember, the key is to understand the structure of your code and your specific needs, as the use of require() and define() can vary based on the context.

In SuiteScripts, require() and define() are both used to load modules, but they are typically used in different contexts.

1. require():

  • Used to import and use modules in most parts of your SuiteScript code.

  • Commonly used to load modules within functions, event handlers, or other areas where you need to import modules dynamically or conditionally.

  • Suitable for most situations outside of SuiteScript entry points.

suitescript require()

2. define():

  • Used specifically in SuiteScript entry points, such as Suitelet, Map/Reduce, Scheduled Script, etc.

  • The define() function is used to define the module and specify its dependencies.

  • It ensures that all dependencies are loaded before executing the entry point code.

suitescript define()

When to use each:

  • Use require() for loading modules in most of your SuiteScript code outside of entry points.

  • Use define() specifically in SuiteScript entry points to ensure proper module loading and execution order.


  • In terms of performance, there isn't a significant difference between require() and define() when it comes to module loading. The primary consideration is ensuring that dependencies are loaded in the correct order.

Note: SuiteScripts follow the Asynchronous Module Definition (AMD) pattern for module loading, and both require() and define() are part of the AMD API provided by NetSuite SuiteScript 2.0.

While the provided information aims to guide the usage of require() and define(), it is crucial to understand that specific contexts and code structures can significantly impact their application.

Please note:

  • This information serves as a general guideline, not a definitive solution.

  • Always double-check your individual script to fully grasp the context and potential issues involving require() and define().

  • Consider seeking further assistance from relevant documentation or experienced developers for complex scenarios.


When tackling module loading in SuiteScript, remember that both require() and define() have their places. While they share the goal of bringing modules into your code, their application differs based on context and purpose.

  • For dynamic loading within functions or event handlers, lean towards require(). It offers performance benefits by loading modules only when needed.

  • When it comes to SuiteScript entry points, define() takes the helm. It ensures proper dependency management and execution order.

The key lies in understanding your code structure and specific needs. Consider the performance gains of lazy loading with require() while ensuring order in entry points with define().

Remember, this is a guiding principle, not a set rule. Complex scenarios might require deeper understanding and assistance from documentation or experienced developers.

By carefully choosing between require() and define(), you can write well-structured, efficient, and maintainable SuiteScript code.

At Etter+Ramli Asia, we understand the complexities of working with NetSuite and are dedicated to helping users overcome these challenges. Our team of certified experts can provide further insights and support to ensure you're getting the most out of your NetSuite experience.

Etter+Ramli as the Trusted, Independent Managed Services Provider for NetSuite

Using NetSuite Managed Services could be your growing company's best strategic move. NetSuite Managed Services offers a comprehensive solution, granting companies access to a team of experienced NetSuite administrators and consultants to manage their NetSuite ERP. Typically, this service is more affordable than hiring in-house staff. When you use managed services, your systems are always up-to-date. In the world of IT, systems are consistently upgraded and patched and come with a slew of security protocols. It is a lot to handle, but your teams can handle this when implementing managed services.

The goal is to ensure your NetSuite instance supports your business’ growth.

For over 20 years, Etter+Ramli has helped several companies optimize their NetSuite software solution. With a 95% customer satisfaction rate, Etter+Ramli can provide your company with world-class support, Certified NetSuite experts, and a value-based pricing structure.

Etter+Ramli As Your Extended NetSuite Team

Etter+Ramli is an Independent Managed Success Provider for NetSuite clients. We are NOT partnered with Oracle NetSuite and do not take commissions. We bring our knowledge, expertise, and passion for success to our clients. We help clients Buy, Deploy, Grow, and Abandon NetSuite. We engage as a client-side managed service to ensure our priorities align with our clients.

To explore the benefits of retaining Etter+Ramli as your Managed Success Provider, contact Todd Kimpton or visit the website for a free consultation today.

Subscribe to our Newsletter: SuiteWords of Etter+Ramli and stay up-to-date with the latest trends on NetSuite, tips n’ tricks, productivity solutions, and events.


bottom of page