Monday, April 22, 2019

Basic transaction search over web services using PHP Toolkit version 2012.2

Basic transaction search can be used for any type of transaction.
The advantage of this type of search is that it returns also values from other records (in opposite to advanced transaction search).
The code below is using PHP Toolkit v2012.2 and is designed for searching one or more transactions based on internal IDs:

require_once 'PHP_Toolkit_2012_2/NetSuiteService.php'; //include the PHP toolkit service library$service = new NetSuiteService(); //initialize the netsuite service - the main object$search = new TransactionSearchBasic(); //search for transaction in BASIC mode$RecordRefsIDs = Array('1551', '21687', '21696'); //IDs of transactions to search for$SearchMultiSelectField = new SearchMultiSelectField(); //set up multiselect field to which IDs will be put$RecordRefs = Array(); //array to hold IDs of transactions to search for//fill array of record references with RecordRef objectsfor($i = 0; $i < sizeof($RecordRefsIDs); $i++) {	$RecordRef = new RecordRef(); //each ID needs to be presented as RecordRef	$RecordRef->internalId = $RecordRefsIDs[$i];  //here the ID is put as RecordRef internal ID	array_push($RecordRefs, $RecordRef); // add the ID, now as RecordRef to array of such objects so it can be used for searching}$SearchMultiSelectField->searchValue = $RecordRefs; //put IDs of transactions to search for as a search value$SearchMultiSelectField->operator = 'anyOf'; //set operator according to which search will be executed. Values are anyOf or noneOf$search->internalId = $SearchMultiSelectField; //IDs in form of multiselect field are assigned for search on search object$request = new SearchRequest(); //common search $request->searchRecord = $search; //specifying BASIC transaction search to common search$searchResponse = $service->search($request); //execute the search and gather responseecho "&lt;pre&gt;";var_dump($searchResponse); // dump the response on the screen so it is easy to search through the returned objectecho "&lt;/pre&gt;";

No comments:

Post a Comment