Creating the same Sales Order for multiple Customers can be repetitive and prone to mistakes if done manually. As an Administrator, you want a faster and more reliable way. With record.copy() function, you can duplicate an existing Sales Order and assign it to different customers in just a few clicks—or even automate the entire process with a SuiteScript.
How It Works
- Pick a template Sales Order you want to copy (e.g., SO #5185).
- Create a list of Customer IDs who should get the new orders.
- Use a For loop to go through each customer in the list.
- For each customer, the script uses the record.copy() method to duplicate the Sales Order.
- Replace the Customer field (entity) with the current Customer ID from the loop.
- Add a memo for traceability in Memo field (e.g., “Copied from Sales Order #5185”).
- Save the Sales Order, and will assign it a brand-new Sales Order ID.
Sample Script
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
*/
define(['N/record'], function(record) {
function onRequest(scriptContext) {
var entityId=[1,1904,790];
var entityLength=entityId.length;
var a;
for (a=0;a<entityLength;a++){
var newSalesOrder = record.copy({
type: record.Type.SALES_ORDER,
id: 5185,
isDynamic: true
});
newSalesOrder.setValue({
fieldId: 'entity',
value: entityId[a]
});
newSalesOrder.setValue({
fieldId: 'memo',
value: 'Copied from Sales Order #5185'
});
// Save the new record
var newRecordId = newSalesOrder.save();
log.debug('--------', entityId[a]);
log.debug('New Sales Order created with ID', newRecordId);
}
}
return {
onRequest: onRequest
};
});
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!