NetSuite SuiteScript 2.0: Load a search and add filter expressions

Here’s how you can add filter expressions in NetSuite SuiteScript 2.0

In NetSuite, filter expressions to your SuiteScript 2.0 code go two ways. First is when you want it’s just a simple filter and does not have any formulas.

var objContracts = search.load({
 id: SEARCH_HEADER
 });
 var filterArray = [];
 filterArray.push([field1,'anyof', STATUS_ACTIVE]);
 filterArray.push('and');
 filterArray.push([field2,'anyof', CUSTOMER]);
 objContracts.filterExpression = filterArray;
 var filters = objContracts.filterExpression;
 var arrResult = objContracts.run();
 var arrResultSet = arrResult.getRange({
 start: 0,
 end: 100
 })

With formula

What if you want to add a formula? Let us show you how:

var objContracts = search.load({
 id: SEARCH_HEADER
 });
 var formulaString = "formulanumeric: CASE WHEN {custrecord_qnz_con_hdr_bal_volume} > 1000 THEN 1 ELSE 0 END";
 var filterArray = [];
 filterArray.push(['field1','anyof', STATUS_ACTIVE]);
 filterArray.push('AND');
 filterArray.push(['field2','anyof', stCustomer]);
 filterArray.push('AND');
 filterArray.push([formulaString, "equalto", "1"]);
 objContracts.filterExpression = filterArray;
 var filters = objContracts.filterExpression;
 var arrResult = objContracts.run();
 var arrResultSet = arrResult.getRange({
 start: 0,
 end: 100
 })

Want to learn more about searching in SuiteScript 2.0? You may watch some good Youtube videos on this link.

Hope you find this helpful!

Do you have NetSuite Development needs? Do you need help with a solution like this? Click on the link below and let’s have a chat about your project requirements!

Contact us for your NetSuite needs!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s