๐งฉ Dynamic SuiteScript Configuration Framework (Parameter-Driven Logic)
Introduction
Have you ever duplicated a script just to change a form ID, saved search, or customer type?
Thatโs a common pain point in NetSuite development โ but itโs completely avoidable.
By building a Dynamic Configuration Framework, you can make your SuiteScripts flexible, reusable, and environment-agnostic.
This framework uses script parameters, custom records, and configuration lookups to drive logic dynamically โ no more hardcoding IDs or constants.
๐ก Why Build a Configuration Framework?
Challenge | Without Framework | With Framework |
---|---|---|
Hardcoded IDs | Script must be edited for each client/site | Configurable per deployment |
Repeated Code | Multiple script versions for same process | One reusable codebase |
Error-Prone | Developers forget to change constants | Controlled via config record |
Limited Scalability | Difficult to maintain | Fully environment-independent |
โ Goal: One script, multiple uses โ easy to deploy, configure, and audit.
๐งฑ Step 1: Create a Configuration Custom Record
Name: Script Configuration
ID: customrecord_script_config
Field Label | ID | Type | Description |
---|---|---|---|
Script Key | custrecord_script_key | Text | Unique identifier (e.g., โInvoice_Updateโ) |
Saved Search ID | custrecord_search_id | Text | ID of saved search |
Form ID | custrecord_form_id | Integer | Custom Form internal ID |
Account ID | custrecord_account_id | Integer | GL account ID |
Subsidiary | custrecord_subsidiary | List | Apply config to specific subsidiary |
Status | custrecord_config_status | List | Active / Inactive |
Notes | custrecord_config_notes | Long Text | Documentation |
โ๏ธ Step 2: Create a Utility Module to Fetch Configuration
/**
* @NApiVersion 2.1
* @NModuleScope Public
*/
define(['N/search'], (search) => {
function getConfig(scriptKey, subsidiaryId) {
const configSearch = search.create({
type: 'customrecord_script_config',
filters: [
['custrecord_script_key', 'is', scriptKey],
'AND', ['custrecord_subsidiary', 'anyof', subsidiaryId],
'AND', ['custrecord_config_status', 'is', 'Active']
],
columns: ['custrecord_search_id', 'custrecord_form_id', 'custrecord_account_id']
});
const result = configSearch.run().getRange({ start: 0, end: 1 })[0];
if (!result) return null;
return {
searchId: result.getValue('custrecord_search_id'),
formId: result.getValue('custrecord_form_id'),
accountId: result.getValue('custrecord_account_id')
};
}
return { getConfig };
});
โ Reusable across any script โ pass your script key and get relevant configuration instantly.
๐ง Step 3: Apply Configuration in Your SuiteScript
define(['N/record', 'N/log', './configUtil'], (record, log, configUtil) => {
const execute = () => {
const config = configUtil.getConfig('Invoice_Update', 2); // Subsidiary 2
if (!config) {
log.error('No Config Found', 'Please check customrecord_script_config');
return;
}
log.audit('Loaded Config', config);
const searchId = config.searchId;
const formId = config.formId;
const accountId = config.accountId;
// Use values dynamically
const inv = record.create({ type: 'invoice', isDynamic: true });
inv.setValue('customform', formId);
inv.setValue('account', accountId);
inv.save();
};
return { execute };
});
โ You can now change saved searches, forms, or accounts without touching the script โ just edit your config record.
๐งฉ Step 4: Script Parameters + Custom Config (Hybrid)
For smaller deployments, use Script Parameters directly.
Example:
Define parameters in your script deployment:
custscript_form_id
custscript_search_id
Retrieve them in the script:
const formId = runtime.getCurrentScript().getParameter('custscript_form_id');
const searchId = runtime.getCurrentScript().getParameter('custscript_search_id');
โ Ideal for per-deployment tweaks without new records.
๐ Step 5: Environment-Aware Configurations
Add a field in your custom record:
Field | ID | Description |
---|---|---|
Environment | custrecord_env_type | Sandbox / Production |
Then use this filter in your utility:
['custrecord_env_type', 'is', runtime.envType]
โ Ensures scripts automatically pick the right settings based on where they run.
โก Step 6: Configuration Validation on Deploy
Add a pre-execution validation in your script:
if (!config || !config.searchId) {
throw Error('Invalid Configuration: Missing Saved Search ID');
}
โ Helps catch setup issues before processing records.
๐งฎ Step 7: Central Dashboard for Configuration Management
Create a Saved Search or SuiteAnalytics Workbook:
- Columns: Script Key, Subsidiary, Status, Updated Date
- Filters:
Status = Active
- Purpose: Monitor which configurations are in use
Optionally, build a Suitelet-based โConfig Management Dashboardโ to allow non-technical users to edit configuration via UI.
๐งฐ Step 8: Real-World Use Cases
Scenario | Description |
---|---|
Multi-Subsidiary Scripts | One script fetches config by subsidiary ID dynamically. |
EDI Integration | Configure endpoints, credentials, and search IDs without editing code. |
Custom Reports | Define saved search IDs and filters externally. |
PDF Templates | Load custom form ID per subsidiary or department. |
Automated Postings | Change GL account IDs via configuration. |
๐งฉ Step 9: Benefits for Developers & Admins
โ
One codebase across environments
โ
No redeployment needed for logic changes
โ
Easy to audit & document
โ
Ideal for integration-heavy systems
โ
Supports both sandbox and production with zero code changes
โ๏ธ Step 10: Best Practices
Category | Tip |
---|---|
Security | Restrict config record edit access to Admin/Developer roles only. |
Performance | Cache results using N/cache for repeated lookups. |
Versioning | Track changes in config records using System Notes. |
Documentation | Add a Notes field for change summaries. |
Testing | Validate config in Sandbox before deploying. |
๐ Related Tutorials
- ๐ Performance Optimization for Map/Reduce Scripts
- ๐ Integration Logging & Monitoring Dashboard
- ๐ Custom Error Handling & Retry Framework
โ FAQ
Q1. Can admins update configurations without script access?
Yes โ by using custom records and role-based permissions.
Q2. Can configurations differ per subsidiary or customer type?
Yes โ just add those fields in your configuration record.
Q3. How does this compare to SuiteScript parameters?
Custom records are more flexible for multi-environment and multi-tenant setups.
Q4. Is caching necessary?
Yes โ caching improves performance by avoiding repeated search calls.
๐งญ Summary
A Dynamic Configuration Framework transforms your SuiteScript architecture into a scalable, modular, and reusable system.
Instead of rewriting code, you define your logic externally and deploy it instantly โ saving time, improving maintainability, and reducing deployment risk.
This approach is a hallmark of enterprise-level NetSuite customization, used by leading solution providers for integrations, automation, and global rollouts.
Leave a Reply