RE: 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.



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);

fabriziomangiapane Rookie Asked on July 22, 2020 in How To's.
Add Comment
3 Answers

Do you need to store the value? If not you can populate a custom field using a saved search.

Rookie Answered on July 22, 2020.

Yes, i need to store the value for other reports and forms

on July 22, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.