how to create a “Total Quantity” Field on Sales Order
Hi, i need to create a Field on the record “Sales Order” with the total of all the quantity of items lines in the order.
e.g.
_______________
Item quantity
socks 3
gloves 2
__________________
total quantity 5
I tried with Scriptsuite but the value is null if the transaction is added through an external flow (as an integration). it only works when a validation trigger works (for example, when I manually click “add” or “edit” in the item line)
/* * Client script function for Update TOT QTY */ function updateTotalQuantity(type, name) { //initialize variable for total quantity var totalQuantity = 0; // count number of lines in 'item' sublist var itemCount = nlapiGetLineItemCount('item'); //for each line in the 'item' sublist, add value in quantity column to the total quantity variable for(var i=1; i<=itemCount; i++){ lineLevelQuantity = nlapiGetLineItemValue('item', 'quantity', i) if(lineLevelQuantity != '' && lineLevelQuantity != null ) { totalQuantity += parseInt(lineLevelQuantity); } } // assuming custbody_totalqty is the custom body field for the total quantity, change its value based the value from the computation above nlapiSetFieldValue('custbody_totalqty', totalQuantity, false); } thanks
Do you need to store the value? If not you can populate a custom field using a saved search.
Yes, i need to store the value for other reports and forms
Use the same script logic in a User event/ Workflow action script in after Submit Script context.
Set value in context.newRecord
then apply for all contexts.
thank you for your reply!
I created a new user eventscript, entering the action in “after submit” function. I deployed it to Sales orders. where should I set this “Set value in context.newRecord”?
afterSubmit(context)
context.newRecord.setValue(‘fieldId’,fieldvalue) in afterSubmit