Scripting

Referencing the Licentra Library

To utilize the Licentra API within your SuiteScript 2.x scripts, you must include the licentra_lib module in your script's define statement. This makes the Licentra functions available for use in your custom scripts.

See More: Licentra Wiki – Modules


Bundle Path

The Licentra library is referenced using its standard bundle path:

Code
'/SuiteBundles/Bundle 571165/licentra_lib'

Module Inclusion

Basic Inclusion

Here's how to include the Licentra library in your script's define statement:

Code
/** * @NApiVersion 2.1 * @NScriptType UserEventScript * @NModuleScope SameAccount */ define( [ '/SuiteBundles/Bundle 571165/licentra_lib', // Include the Licentra library ], (licentraLib) => { // Your script logic here } );

With Other Libraries

When using multiple libraries, include Licentra alongside your other dependencies:

Code
/** * @NApiVersion 2.1 * @NScriptType UserEventScript * @NModuleScope SameAccount */ define( [ './libraries/hc360_lib_setup', './libraries/hc360_lib_ue', '/SuiteBundles/Bundle 571165/licentra_lib', // Include the Licentra library ], (hc360Setup, hc360UE, licentraLib) => { // Your script logic here } );

Module Aliasing

The licentra_lib module is typically aliased as licentraLib in the define callback function for clarity and consistency.

Complete Example

Here's a complete example demonstrating how to include and use the Licentra library in a User Event script:

Code
/** * @NApiVersion 2.1 * @NScriptType UserEventScript * @NModuleScope SameAccount */ define( [ './libraries/hc360_lib_setup', './libraries/hc360_lib_ue', '/SuiteBundles/Bundle 571165/licentra_lib', // Include the Licentra library ], (hc360Setup, hc360UE, licentraLib) => { // Define the feature ID as configured in Licentra const fdaFeature = 'OPEN_FDA'; /** * @param {UserEventContext.beforeLoad} context */ const beforeLoad = (context) => { const fn = 'beforeLoad'; try { hc360UE.setDependencies(hc360Setup); // Call the isFeatureEnabled method from the licentraLib const featureStatus = licentraLib.isFeatureEnabled(fdaFeature); const isFDAEnabled = featureStatus.enabled; // Access the 'enabled' property log.debug({ title: 'Is_FDA_ENABLED', details: isFDAEnabled }); log.debug({ title: 'FDA_FEATURE_MESSAGE', details: featureStatus.message }); if (!isFDAEnabled) { // Logic to handle disabled feature, e.g., hide button, show message log.audit({ title: 'Licentra Feature Disabled', details: `Feature "${fdaFeature}" is disabled. Message: ${featureStatus.message}`, }); return; } if (context.type === context.UserEventType.EDIT) { hc360UE.addFDAButton(context.newRecord, context.form); } } catch (error) { log.error({ title: `Error: ${fn}`, details: `Error: ${error.name}: ${error.message} Stack: ${error.stack}`, }); } }; return { beforeLoad, }; } );

Key Points

  • Bundle Reference Path: Always use the exact path /SuiteBundles/Bundle 571165/licentra_lib
  • Module Naming: The licentra_lib module is aliased as licentraLib in the define callback function
  • Feature ID: Define your feature IDs when setting up your licenses in the Licentra platform
  • Error Handling: Always wrap Licentra API calls in try-catch blocks for proper error handling

Troubleshooting

If you encounter issues with the library reference:

  1. Verify Bundle Installation: Ensure the Licentra bundle is properly installed in your NetSuite account
  2. Check Bundle ID: Confirm the bundle ID (571165) is correct for your environment
  3. Module Scope: Ensure your script has the appropriate module scope (SameAccount or Public)
  4. Script Type: Verify the script type supports external module references
Last modified on