As an administrator, you may frequently encounter scenarios where you need to duplicate existing transactions—such as creating repeat invoices for loyal customers, replicating purchase orders, or preparing test data in your sandbox. Doing this manually can be time-consuming and error prone. Fortunately, SuiteScript 2.1 offers a solution: the record.copy.promise method.
This method allows you to asynchronously duplicate a record—such as a Sales Order, Invoice, or other supported transaction—while preserving all data from the source record. This approach is efficient, reduces manual effort, and ensures data consistency across your business processes.
Here’s the approach:
- Identify the Record to Copy: Determine the internal ID of the transaction you want to duplicate. This ensures the correct record is copied.
- Use record.copy.promise to Duplicate the Record: This method creates a new instance of the original transaction while preserving its data. It also supports asynchronous execution, so your script won’t block other operations.
- Modify Fields if Needed: Once copied, you can update any fields on the new transaction. Common updates include adding a memo, changing the customer, or adjusting item quantities.
- Save the New Record: After making modifications, save the new transaction to create it in the system. Always capture the new record’s internal ID for tracking and reference.
- Log and Handle Errors: Log the new record ID for auditing purposes and wrap your logic in error handling to manage unexpected issues during copying or saving.