• : 1-877-596-8218
  • : sales@aecc.ca
# # #
#

Advanced Search Using Expressions in SuiteScript.

Saved Search in NetSuite is a powerful feature. In the UI, one can build a saved search using expressions. To do this, check the “USE EXPRESSIONS” box.


In the picture, the searching criteria is “Account is A/D Furniture&Fixtures” OR “ Amount is less than 1”. In SuiteScript, we can build the same search that using “and/or” search expression using parentheses. For example, we want to build a saved search that has the following criteria:

Criteria : (Item =ItemID1 & OrderType=OrderTypeId1 & OrderTypeUsage=OrderTypeUsageId1)
Or (Item =ItemID2 & OrderType=OrderTypeId2 & OrderTypeUsage=OrderTypeUsageId2)
Or (Item =ItemID3 & OrderType=OrderTypeId3 & OrderTypeUsage=OrderTypeUsageId3)

The following script demonstrates how to achieve this


var transactionDate = record.getFieldValue('trandate');
	var filters = [];
	var fExp = [];
	for ( i = 0; i < data.length; i += 1) {
		filters.push(['custrecord_tintri_order_type_item', 'anyof', data[i].item]);
		filters.push('and');
		//Make sure not empty
		if (!isEmpty(data[i].orderType)) {
			filters.push(['custrecord_tintri_order_type', 'anyof', data[i].orderType]);
		} else {
			filters.push(['custrecord_tintri_order_type', 'anyof', '@NONE@']);

		}
		filters.push('and');
		//Make sure not empty
		if (!isEmpty(data[i].orderSubtype)) {
			filters.push(['custrecord_tintri_order_subtype', 'anyof', data[i].orderSubtype]);
		} else {
			filters.push(['custrecord_tintri_order_subtype', 'anyof', '@NONE@']);

		}
		filters.push('and');
		//Make sure not empty
		if (!isEmpty(data[i].orderTypeUsage)) {
			filters.push(['custrecord_tintri_order_type_usage2', 'anyof', data[i].orderTypeUsage]);
		} else {
			filters.push(['custrecord_tintri_order_type_usage2', 'anyof', '@NONE@']);

		}
		filters.push('and');
		filters.push(['custrecord_tintri_suitegl_rule_start', 'onOrBefore', transactionDate]);
		filters.push('and');
		filters.push(['custrecord_tintri_suitegl_rule_end', 'onOrAfter', transactionDate]);
		filters.push('or');

	}

	filters.pop();