Same order, two sales orders
An external system sends order A-1042 and NetSuite creates the sales order. The response never arrives because of a network drop. The system retries… and without protection, a second order is created.
The fix is to make retries safe (idempotency). Use the external system’s identifier as the External ID: NetSuite won’t allow two records of the same type with the same External ID.
// RESTlet (SuiteScript 2.1): look up before creating
const existing = query.runSuiteQL({
query: 'SELECT id FROM transaction WHERE externalid = ?',
params: [payload.orderId]
}).asMappedResults()[0];
if (existing) return { id: existing.id, duplicate: true };
const so = record.create({ type: record.Type.SALES_ORDER });
so.setValue({ fieldId: 'externalid', value: payload.orderId });
If the order already exists, you return the same one. The External ID is the second safeguard: even if two requests arrive at once, NetSuite rejects the duplicate.