Administrators often need to perform bulk updates on Vendor Bill records, such as updating the Memo and/or Department fields for multiple transactions. Loading and saving each record individually can be slow and consume unnecessary governance.
A more efficient approach is to update only the required standard body fields using record.submitFields.promise() within a Scheduled Script.
This method allows you to:
- Update standard body fields only
- Avoid using record.load() and record.save()
- Improve script performance and governance usage
- Safely process records in bulk
Example: Bulk Update Vendor Bill Memo and Department
- Searches Vendor Bills using mainline = T
- Updates the Memo and Department fields
- Logs successful updates and errors for easier monitoring
/**
* @NApiVersion 2 .1
* @NScriptType ScheduledScript
*/
define(['N/record', 'N/search', 'N/log'], (record, search, log) => {
/**
* Entry point for the scheduled script.
*/
const execute = async (context) => {
// Search for the most recent vendor bills
const vendorBillSearch = search.create({
type: record.Type.VENDOR_BILL,
filters: [['mainline', 'is', 'T']],
columns: ['internalid']
});
// Collect up to 5 vendor bill IDs for this example
let vendorBillIds = [];
vendorBillSearch.run().each(result => {
vendorBillIds.push(result.getValue({ name: 'internalid' }));
return vendorBillIds.length < 5; // Limit for demonstration
});
// Update each Vendor Bill
for (let billId of vendorBillIds) {
try {
await record.submitFields.promise({
type: record.Type.VENDOR_BILL,
id: billId,
values: {
memo: 'Updated by Scheduled Script',
department: 2 // Set to department internal ID as an example
}
});
log.audit(
'Vendor Bill Updated',
`Vendor Bill ID ${billId} updated with new memo and department.`
);
} catch (error) {
log.error('Error Updating Vendor Bill', `ID: ${billId} | Details: ${error.message}`);
}
}
};
return { execute };
});
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!