Shelby Owens
03/18/2025, 6:40 PMCeligo AI
03/18/2025, 6:40 PMAI generated answer (using internal Slack threads):Based on the conversations, here is a good starting point for creating an after submit user event on Sales Orders: 1. Create a User Event Script: This script will be triggered after a Sales Order is submitted. In SuiteScript, this is done by defining an
afterSubmit
function in your script file.
2. Identify the Subsidiary: In the afterSubmit
function, you can access the Sales Order record and get the subsidiary using context.newRecord.getValue('subsidiary')
. You can then check if it matches the subsidiary you are interested in.
3. Calculate the Total of Inventory Items: You can iterate over the line items in the Sales Order and sum up the total of inventory items. This can be done using context.newRecord.getLineCount('item')
to get the number of line items and context.newRecord.getSublistValue('item', 'quantity', i)
to get the quantity of each item.
4. Add an Item for 25% of the Total: Once you have the total, you can calculate 25% of it and add a new line item to the Sales Order with this quantity. This can be done using context.newRecord.selectNewLine('item')
, context.newRecord.setCurrentSublistValue('item', 'item', itemId)
, context.newRecord.setCurrentSublistValue('item', 'quantity', quantity)
, and context.newRecord.commitLine('item')
.
Here is a sample code snippet based on the above steps:
javascript
function afterSubmit(context) {
var salesOrder = context.newRecord;
var subsidiary = salesOrder.getValue('subsidiary');
if (subsidiary == 'your_subsidiary_id') {
var lineCount = salesOrder.getLineCount('item');
var total = 0;
for (var i = 0; i < lineCount; i++) {
var quantity = salesOrder.getSublistValue('item', 'quantity', i);
total += quantity;
}
var additionalItemQuantity = total * 0.25;
salesOrder.selectNewLine('item');
salesOrder.setCurrentSublistValue('item', 'item', 'your_item_id');
salesOrder.setCurrentSublistValue('item', 'quantity', additionalItemQuantity);
salesOrder.commitLine('item');
}
}
Please replace 'your_subsidiary_id'
and 'your_item_id'
with the actual ID of your subsidiary and item.
******
Disclaimer:
This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes.
******Celigo AI
03/18/2025, 6:41 PMSlack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.840014577
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.830630183
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.828262
Celigo AI
03/18/2025, 6:41 PM