Saturday, May 11, 2019

How to get sum of all "Item Rates" for a given order via Workflow Action Script

One way to get the sum of all Item Rates present on the sales order is to use a WF action script.

- Create a WF deployed on sales order

- Create a new action script, refer to the code below :

function getItemRate(){
var rec= nlapiGetNewRecord();
var id= rec.getId();
var rates;
var param=nlapiGetContext().getSetting('SCRIPT', 'custscriptxx'); //Account X passed as parameter to the script

var filters = new Array();
var columns= new Array();

filters[0]= new nlobjSearchFilter('internalid', null, 'is', id);
filters[1]= new nlobjSearchFilter('account', null, 'is', param);
columns[0] = new nlobjSearchColumn('rate', null, 'sum');

var searchresults=nlapiSearchRecord('salesorder',null, filters, columns);
if (searchresults !=null){
rates = searchresults[0].getValue('rate', null, 'sum')
}
nlapiLogExecution('DEBUG', 'total rate', rates);
return rates;

}

- You can add parameter to hold the value of Account (custscriptxx).

- When calling the Action script from the WF, the internal id of the Account will be passed and Store Result in, set the above a custom workflow field.

 

No comments:

Post a Comment