ANS-1435 · SUITESCRIPT DEVELOPMENT
How to Programmatically Create a NetSuite Work Order from a Sales Order Line
This guide outlines the SuiteScript 2.x method for programmatically creating and linking a Work Order to a specific Sales Order line.
Short answer
To programmatically create a Work Order from a Sales Order line, instantiate a new Work Order record. Set its "soid", "soline", and "specord" fields, then save it. Retrieve the new Work Order's internal ID. Update the original Sales Order line's "woid" field with this ID and save the Sales Order to establish the link.
Scenario
When managing transactions with line items requiring Work Order creation, users can typically click a 'Create WO' link in the NetSuite UI. However, when transactions are generated programmatically via SuiteScript, a method is needed to replicate this functionality to ensure the Work Order is correctly linked to the specific transaction line.
Solution
While NetSuite now documents the use of the CPQM-MR-WOC map/reduce script for creating work orders from sales orders via SuiteScript 2.x, an alternative method involves directly creating a Work Order record and setting specific fields to establish the link. Attempting to simply set the 'Create WO' field to true or input an ID on the transaction line is insufficient for this purpose. The approach outlined below is derived from observing the URL parameters used when creating a Work Order from the UI.
When a user clicks the 'Create WO' link in the UI, the URL typically resembles:
/app/accounting/transactions/workord.nl?soid=94023&soline=1&specord=T&entity=662&assemblyitem=878&quantity=1
To replicate this functionality programmatically:
Create a new Work Order record using SuiteScript.
Set the following fields on the new Work Order record:
woRecord.setValue({fieldId: 'soid', value: soRecord.id}); //the transaction id
woRecord.setValue({fieldId: 'soline', value: assemblyLineNumber}); // the line number for the work order item on the transaction (be careful with ss 1.0 vs 2.0)
woRecord.setValue({fieldId: 'specord', value: true}); //This field is required for proper linking.Save the newly created Work Order record to obtain its internal ID.
Load the original Sales Order record.
Set the
woidfield on the relevant item sublist line of the Sales Order to link it to the new Work Order:
soRecordLoaded.setSublistValue({
sublistId: 'item',
fieldId: 'woid',
line: assemblyLineNumber,
value: woInternalId
});Save the updated Sales Order record.
Expert NetSuite Support
Need help with this NetSuite issue?
SuiteScript Development consulting and configuration support
