Adding a specific item to any new Sales Order before saved
Hello,
I am trying to create and deploy a SuiteScript but nothing is happening.
With the script below I want to automatically add an item to any new Sales Order before the SO is saved.
I have the Script Type set to User Event, I have the Before Submit Function checked, and under the Deployment record I have it apply to Sales Order in Testing with an Event Type as Submit
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define([‘N/record’],
function (record) {
function beforeSubmit(context) {
if (context.type === context.UserEventType.CREATE) {
var salesOrder = context.newRecord;
salesOrder.selectNewLine({
sublistId:’item’
});
salesOrder.setCurrentSublistValue({
sublistId:’item’,
fieldId:’item’,
value: 2231
});
salesOrder.setCurrentSublistValue({
sublistId:’item’,
fieldId:’quantity’,
value:1
});
salesOrder.commitLine({sublistId:’item’});
}
}
return {
beforeSubmit:beforeSubmit
};
});
Hi,
Event Type as Submit and context.type === context.UserEventType.CREATE are different.
I would suggest removing the event type from the script deployment as a first step to check if it works.
Thanks,
Chris
Hello,
You can achieve this with a workflow and an add line action, specifying the Item



