This is my code so far: ```var salesOrder = recor...
# suitescript
p
This is my code so far:
Copy code
var salesOrder = record.create({
    type: record.Type.SALES_ORDER, 
    isDynamic: false,
    defaultValues: null 
});
salesOrder.setValue({
    fieldId: 'entity',
    value: '20310'
});

salesOrder.save({
    enableSourcing: true, 
    ignoreMandatoryFields: false
});
b
do you want to create and save the sales order, and then redirect the user to it?
p
nope. wanted to create and then let the user save it. there are some required fields that the user needs to fill in before saving.
b
then you want to do a different approach
redirect the user to the new sales order, and then set your field values
if you only have entity, (or body fields for that matter) there are url parameters you can set to default the values
p
ah. ok. thanks!
t
I think the best approach here is to create a workflow. Use the add button action to add a button to the record that you want to display the button. Then, when the user clicks the button, move the workflow to the next state which will have a redirect to record action. The redirect to record action allows you to set default values in the new record.
p
My one issue with the workflow is that I could not map the subsidiary. Plus, isn't there a limit on how many fields you can map?
n
mapping the subsidiary is an enhancement according to NS support . I call it a defect though.
👍 2
n
You may be better doing the whole button script "trinity". 1. User event to add the button / include the client script 2. Client script button function directs to a SuiteLet 3. Suitelet - form based and on GET allows the user to specify those fields you want to populate. on POST the suitelet creates the SO and redirects to that SO
Or create a menu link to the Suitelet dispensing with the button UE and client script altogether
p
thanks @NElliott. Will give that a try.