Friday, September 21, 2018

Use Formula Columns on SuiteScript Searches

A NetSuite user wants to have a column in his script search which uses formulas i.e. formulatext, formulanumeric, formuladate

To use a formula in nlobjSearchColumn objects, one needs to use the setFormula method of the object. Here is a simple example:
 

function searchWithFormula() {
var columns = new Array();
columns[0] = new nlobjSearchColumn('formulatext');
columns[0].setFormula("CASE WHEN {quantitycommitted}-{quantity}<0 THEN 'Some Items Committed' ELSE 'Fully Committed' END") ;

var results = nlapiSearchRecord('salesorder', null, null, columns);

for(var i in results) {
  var result = results[i];
  nlapiLogExecution('DEBUG', 'Record Type is: ', result.getRecordType());
  nlapiLogExecution('DEBUG', 'Record ID is: ', result.getId());
  nlapiLogExecution('DEBUG', 'Commitment Status: ', result.getValue(columns[0]));
}
}

 


 
The result of this script is detailed on the screenshot below:

Image

No comments:

Post a Comment