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
Rookie Asked on July 22, 2020 in How To's.
Add Comment
3 Answer(s)

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

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.

Rookie Answered on July 23, 2020.
Add Comment

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”?

Rookie Answered on July 27, 2020.

afterSubmit(context)

context.newRecord.setValue(‘fieldId’,fieldvalue) in afterSubmit  

on July 31, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Limebox   Become a Sponsor