Netsuite | Search PHP webservice – sample code

As per the Suite Talk Web Services Platform Guide; The search operation is used to execute a search on a specific record type based on a set of criteria. You can search by defining search filter fields on the record, joined fields on an associated record, search return columns, or joined search return columns from an associated record. The results of the search can be complete records, or a select set of fields specified through search return columns. This example will guide developer how to perform a search operation thru web service using PHPToolkit.

require_once 'PHPtoolkit.php';
require_once 'login_info.php';
global $myNSclient;

# SEARCH EMPLOYEE
# ===============

//create a search value
$strFirstname = "E";

$employeeSearch = new nsComplexObject("EmployeeSearchBasic");
$employeeSearch->setFields(array("firstName" => array(
"operator" => "startsWith",
"searchValue"=> $strFirstname,
"operatorSpecified" => true)));

$myNSclient->setSearchPreferences(false);

try
{
	$searchResponse = $myNSclient->search($employeeSearch);
	$totalRecords = $searchResponse->totalRecords;
	if ($totalRecords > 0)
	{
		foreach ($searchResponse->recordList as $record)
		{
		$employee_internalId = $record->getField('internalId');
		$employee_firstname = $record->getField('firstName');
		$employee_lastname = $record->getField('lastName');
		echo "Internal Id: ". $employee_internalId;
		echo "First Name: " . $employee_firstname;
		echo "Last Name: " . $employee_lastname;
		}
	}
	else
	{
		echo "No result found.";
	}

}
catch (Exception $e)
{
	echo "Employee is not found. Please try again.";
	exit();
}

Related posts:

  1. Netsuite | PHP webservice Delete operation – code sample
  2. Netsuite | GetSelectValue PHP webservice code sample
  3. Netsuite | AsyncAddList .NET webservice code sample

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>