Managing Customer credit limits one record at a time can be time-consuming—especially when policies change, or thresholds need to be adjusted across many customers. A Scheduled Script is an efficient and safe way to bulk-update customer credit limits based on defined criteria.
This tip walks through a simple example that automatically increases credit limits for active customers whose current credit limit falls below a specific threshold.
You want to:
- Identify active customers
- Check if their credit limit is below a defined amount
- Automatically update their credit limit to a new value
- Log each update for audit and troubleshooting purposes
Key Highlights of the Script
- Uses a Saved Search–style approach via N/search
- Updates records efficiently using record.submitFields() (no record load required)
- Includes audit and error logging for traceability
- Ideal for one-time bulk updates or recurring policy enforcement
Sample Scheduled Script
/**
* @NApiVersion 2 .1
* @NScriptType ScheduledScript
* @NModuleScope SameAccount
*/
define(['N/search', 'N/record', 'N/log'], function(search, record, log) {
function execute(context) {
// --- CONFIGURATION: Edit these values as needed ---
var creditLimitThreshold = 5000; // Only update customers with credit limit below this amount
var newCreditLimit = 7500; // New credit limit value to set
// Log the start of the bulk update process
log.audit('Bulk Credit Limit Update',
'Starting for all active customers. Threshold: ' + creditLimitThreshold);
// --- SEARCH for active customers with credit limit below the threshold ---
var customerSearch = search.create({
type: search.Type.CUSTOMER,
filters: [
['creditlimit', 'lessthan', creditLimitThreshold], // Only customers below threshold
'AND',
['isinactive', 'is', 'F'] // Only active customers
],
columns: ['internalid', 'entityid', 'creditlimit'] // Retrieve minimal required fields
});
// Process each customer in the search results (up to 1000)
customerSearch.run().each(function(result) {
var customerId = result.getValue({ name: 'internalid' });
var entityId = result.getValue({ name: 'entityid' });
var oldCreditLimit = result.getValue({ name: 'creditlimit' });
try {
// Update only the creditlimit field using submitFields
record.submitFields({
type: record.Type.CUSTOMER,
id: customerId,
values: {
creditlimit: newCreditLimit
}
});
// Log each successful update for traceability
log.audit('Credit Limit Updated',
'Customer ' + entityId +
' (ID: ' + customerId + ') changed from ' +
oldCreditLimit + ' to ' + newCreditLimit);
} catch (e) {
log.error('Update Failed for Customer ID ' + customerId, e.message);
}
return true; // Continue to next customer
});
// Log when the script completes processing
log.audit('Bulk Credit Limit Update', 'Script completed.');
}
return {
execute: execute
};
});
Best Practices
- Test in Sandbox before deploying to Production.
- Schedule during off-peak hours for large customer volumes.
- Review the Execution Log for audit and validation after deployment.
The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. Oracle + NetSuite Inc. does not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations.
Oracle + NetSuite Inc. does not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. Oracle + NetSuite Inc. disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto.
Oracle + NetSuite Inc. shall not be liable for any direct, indirect or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code.
To know more about deploying SuiteScript, check these New to NetSuite Articles.
Do you have another way on how to automate your transactions using SuiteScript? Feel free to share them here!