Maintaining accurate employee email addresses in NetSuite is more than just an administrative task—it directly impacts login access, system notifications, approvals, and overall communication. While updating emails manually may be manageable for one or two employees, it quickly becomes inefficient and error-prone during bulk updates, such as company-wide email domain changes, mergers, or data cleanup initiatives.
As a Administrator, you can leverage SuiteScript Scheduled Scripts to automate employee email updates in a controlled, auditable, and scalable way. This approach minimizes manual effort, reduces the risk of inconsistencies, and ensures updates are applied systematically.
Below is a simple example of a Scheduled Script that updates employee email addresses based on a predefined mapping of internal IDs.
Sample Scheduled Script: Bulk Email Address Update
/**
* @NApiVersion 2.x
* @NScriptType ScheduledScript
*/
define(['N/record', 'N/log'], function(record, log) {
// Mapping of internal employee IDs to their new email addresses
var emailUpdates = {
// userId: 'newemail'
1234: 'empss1@ss1.com',
5678: 'emppsss2@sss2.com'
// Add more mappings as needed
};
function execute(context) {
// Loop through each employee ID in the emailUpdates map
Object.keys(emailUpdates).forEach(function(employeeId) {
try {
// Load the employee record by internal ID
var employeeRec = record.load({
type: record.Type.EMPLOYEE,
id: employeeId
});
// Get the current email address (before update)
var oldEmail = employeeRec.getValue({ fieldId: 'email' });
// Get the new email address from the mapping
var newEmail = emailUpdates[employeeId];
// Update the email field with the new email address
employeeRec.setValue({
fieldId: 'email',
value: newEmail
});
// Save the changes to the employee record
employeeRec.save();
// Log a success message with old and new email addresses
log.audit('Email updated', 'ID: ' + employeeId + ' | Old: ' + oldEmail + ' | New: ' + newEmail);
} catch (e) {
// Log any errors that occur during the process
log.error('Failed to update user ' + employeeId, e.message);
}
});
}
return { execute: execute };
});
Important
- Test in Sandbox: Always validate scripts in a non-production environment before running in production.
- Limit Script Access: Deploy scripts only for admin users to preserve system security.
- Logging & Tracking: Use NetSuite’s logging functionality to audit the outcome and catch any errors.
- Inform Users: Notifying employees about the changes prevents confusion or login issues.
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!