Netsuite PHP Search Tutorials

To perform operations on Netsuite records and objects, it is crucial to understand the 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 is a set of operators supported by SearchStringFieldOperator, and other types of search operators support different sets 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 example of how to search a customer record from an email address. The two methods below accomplish similar results but in a slightly different manner. Choose whichever 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 search 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');
$subsidiary->setFields(
	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);

Share this post

Comments (0)

    No comment

Leave a comment

All comments are moderated. Spammy and bot submitted comments are deleted. Please submit the comments that are helpful to others, and we'll approve your comments. A comment that includes outbound link will only be approved if the content is relevant to the topic, and has some value to our readers.


Login To Post Comment