Scripting

Checking Feature Status

The primary method for developers to interact with Licentra is licentraLib.isFeatureEnabled(featureId). This method queries the Licentra server (via the configured connection) to determine if a given feature is currently enabled for the NetSuite account or user context.

See More: Licentra Wiki – Modules


Method Signature

Code
licentraLib.isFeatureEnabled(featureId: string): { enabled: boolean; message: string; }

Parameters

ParameterTypeDescription
featureIdstringThe unique identifier for the feature as configured in the Licentra platform

Return Object Structure

This method returns an object with the following properties:

PropertyTypeDescription
enabledbooleanA boolean value indicating whether the specified feature is currently active and licensed. true if the feature can be used, false otherwise.
messagestringA descriptive message providing details about the feature's status. This can indicate why a feature is disabled (e.g., "License expired", "Feature not subscribed", "Trial period ended") or confirm it's enabled.

Basic Usage

Here's a simple example of how to check if a feature is enabled:

Code
const featureStatus = licentraLib.isFeatureEnabled('YOUR_FEATURE_ID_HERE'); if (featureStatus.enabled) { // Execute code related to the enabled feature log.debug({ title: 'Feature Enabled', details: `The feature is enabled: ${featureStatus.message}`, }); } else { // Handle the case where the feature is disabled log.audit({ title: 'Feature Disabled', details: `The feature is disabled: ${featureStatus.message}`, }); // You might throw an error, redirect the user, or hide functionality }

Advanced Usage Examples

User Event Script Integration

Code
/** * @param {UserEventContext.beforeLoad} context */ const beforeLoad = (context) => { const featureId = 'OPEN_FDA'; try { const featureStatus = licentraLib.isFeatureEnabled(featureId); if (!featureStatus.enabled) { // Hide UI elements or show warning message log.audit('Feature Disabled', featureStatus.message); // Optionally show a user-friendly message if (context.form) { context.form.addField({ id: 'custpage_feature_disabled', type: 'inlinehtml', label: 'Feature Unavailable' }).setDefaultValue(`<div style="color: red;">${featureStatus.message}</div>`); } return; } // Feature is enabled, proceed with normal functionality log.debug('Feature Enabled', featureStatus.message); // Add feature-specific UI elements if (context.form) { context.form.addButton({ id: 'custpage_fda_button', label: 'FDA Lookup', functionName: 'performFDALookup' }); } } catch (error) { log.error('Licentra API Error', error.message); // Handle API errors gracefully } };

Client Script Integration

Code
/** * @param {ClientScriptContext.pageInit} context */ const pageInit = (context) => { const featureId = 'ADVANCED_REPORTING'; try { const featureStatus = licentraLib.isFeatureEnabled(featureId); if (!featureStatus.enabled) { // Disable buttons or hide sections const advancedButton = document.getElementById('custpage_advanced_report_btn'); if (advancedButton) { advancedButton.style.display = 'none'; } // Show notification to user alert(`Advanced reporting is not available: ${featureStatus.message}`); } } catch (error) { console.error('Error checking feature status:', error); } };

Suitelet Integration

Code
/** * @param {SuiteletContext.onRequest} context */ const onRequest = (context) => { const featureId = 'BULK_IMPORT'; try { const featureStatus = licentraLib.isFeatureEnabled(featureId); if (!featureStatus.enabled) { // Return error response or redirect context.response.write('Feature not available: ' + featureStatus.message); return; } // Proceed with bulk import functionality handleBulkImport(context); } catch (error) { log.error('Suitelet Error', error.message); context.response.write('An error occurred while checking feature status'); } };

Common Feature Status Messages

StatusMessage Examples
Enabled"Feature is active and available"
License Expired"License expired on [date]"
Not Subscribed"Feature not included in current subscription"
Trial Ended"Trial period has ended"
Account Suspended"Account access has been suspended"
Usage Limit Reached"Monthly usage limit exceeded"

Best Practices

  1. Always Check Status: Call isFeatureEnabled() before executing feature-specific code
  2. Handle Errors: Wrap API calls in try-catch blocks
  3. User Feedback: Provide clear feedback to users when features are disabled
  4. Graceful Degradation: Design your application to work without disabled features
  5. Logging: Log feature status checks for debugging and audit purposes
  6. Caching: Consider caching results for performance in frequently called scripts

Integration Points

By integrating licentraLib.isFeatureEnabled() calls at critical points in your scripts, you can dynamically control the availability and behavior of your custom NetSuite solutions based on real-time license and subscription data from Licentra.

Last modified on