Netsuite PHP Search Tutorials

To perform operations on Netsuite records and objects, it is crucial to understand search functionality provided by Netsuite. Netsuite offers basic and advanced search objects on various record types, and their operations are practically the same.

The search results are either an array if there are more than 1 record returned, or an object if there is only 1 record in its result set. As a programmer, the result set must be examined whether it's an array or an object before performing an operation on them.

Netsuite search objects offer a selection of operators, and they differ depending on the field you are searching. The following are a set of operators supported by SearchStringFieldOperator, and other types of search operators support different set of operators. For a complete reference of supported operators, please consult Platform : Types in the Netsuite SuiteTalk Schema Browser.

  • contains
  • doesNotContain
  • doesNotStartWith
  • empty
  • hasKeywords
  • is
  • isNot
  • notEmpty
  • startsWith

Here is an examples on how to search a customer record from an email address. The two methods below accomplishes the similar results but in a slightly different manner. Choose which ever method works better for you.

1. Conventional Search Method.

$params = new nsComplexObject('SearchStringField');
$params->setFields(array('searchValue' => $email, 'operator' => 'contains'));
$search = new nsComplexObject("CustomerSearchBasic");
$search->setFields(array ('email' => $params));
$response = $myNSclient->search($search);

2. Simplified Search Method.

$search = new nsComplexObject('CustomerSearchBasic');
$search->setFields(array("email" => 
		array("operator" => "is", "searchValue" => $email)));
$response = $myNSclient->search($search);

If you're looking for a way to search custom fields, you may be interested in reading How to serach custom fields in Netsuite with PHP. Searching custom fields is done via looping through the Custom Field List, and there is no other way around it.

Here is a little complex example, searching for a customer record with criteria consisting of an email, subsidiary and isInactive (bool).

$brand = 1;  // Internal Id of subsidiary RecordRef.
$subsidiaryRecordRef = new nsRecordRef(array('internalId' => $brand));
$subsidiary = new nsComplexObject('SearchMultiSelectField');
	array('searchValue' => $subsidiaryRecordRef, 'operator' => 'anyOf'));
$bool = new nsComplexObject('SearchBooleanField');
$bool->setFields(array('searchValue' => 'false', 'operator' => 'is'));
$params = new nsComplexObject('SearchStringField');
$params->setFields(array('searchValue' => $email, 'operator' => 'is'));
$search = new nsComplexObject("CustomerSearchBasic");
$search->setFields(array ('email' => $params, 
	'subsidiary' => $subsidiary, 
	'isInactive' => $bool));

$response = $myNSclient->search($search);


Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.