Sunday, March 31, 2019

Display the total quantity of items in a transaction (eg. Sales Order, Item Fulfillment, Item Receipt, Transfer Order)

The article below details a client-side script solution to display the total quantity of items in transactions.
This has been tested on Sales Orders, Item Fulfillments, Item Receipts, and Transfer Order
Note that the script may need to change depending on your account's configuration and customizations, and making the said changes require knowledge in SuiteScript.

1) Create Custom Field that will contain the Total Quantity (see Answer 10089 for more info on creating a custom transaction body field).
 Type : Free-form text
 Display Type: Inline Text
 Store Value: Unchecked

2) Create Client Script with the following 'Recalc' function. Remember to change 'custbody_totalqty' to the ID of the field created in step 1 (see Answer 10553 for more info on creating Script Records):
 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);
 }

3) Deploy the Script created in step 2 to the desired transaction types. (see Answer 10554 for more info on defining a Script Deploment)

**Note: The script above will only affect transactions you Create/Edit after creating the script. Users would need to create a separate Mass Update Script in order to populate the total quantity field for all past transactions.

No comments:

Post a Comment