A NetSuite user wants to have a criteria in his script search which uses formulas i.e. formulatext, formulanumeric, formuladate
To use a formula in nlobjSearchFilter objects, one needs to use the setFormula method of the object. Here is a simple example:
function searchWithFormula() {
var filters = new Array();
filters[0] = new nlobjSearchFilter('formulatext', null, 'startswith', 'a');
filters[0].setFormula('SUBSTR({custbody_stringfield}, 3)');
var results = nlapiSearchRecord('salesorder', null, filters, null);
for(var i in results) {
var result = results[i];
nlapiLogExecution('DEBUG', 'Record Type is: ', result.getRecordType());
nlapiLogExecution('DEBUG', 'Record ID is: ', result.getId());
}
}
var filters = new Array();
filters[0] = new nlobjSearchFilter('formulatext', null, 'startswith', 'a');
filters[0].setFormula('SUBSTR({custbody_stringfield}, 3)');
var results = nlapiSearchRecord('salesorder', null, filters, null);
for(var i in results) {
var result = results[i];
nlapiLogExecution('DEBUG', 'Record Type is: ', result.getRecordType());
nlapiLogExecution('DEBUG', 'Record ID is: ', result.getId());
}
}
This search will return all sales order record where the 3rd character of the custbody_stringfield field starts with "a".
No comments:
Post a Comment