Below is a sample function that accepts a search string and searches for items with item ID that contains the search string and returns the actual Item ID and Average Cost:
function itemsearchadv($srchstr){
$service = new NetSuiteService();
$service->setSearchPreferences(false, 20, true);
$itemSearchField1 = new SearchStringField();
$itemSearchField1->operator = "contains";
$itemSearchField1->searchValue = $srchstr;
$search = new ItemSearchAdvanced();
$basic = new ItemSearchRowBasic();
setFields($basic, array(averageCost=>"averageCost",itemId=>"itemId"));
$search->criteria->basic->itemId = $itemSearchField1;
$search->columns->basic = $basic;
$request = new SearchRequest();
$request->searchRecord = $search;
$searchResponse = $service->search($request);
$test = new NullField();
$test = 'itemId';
if (!$searchResponse->searchResult->status->isSuccess) {
echo "SEARCH ERROR";
}else{
echo "<b>SEARCH SUCCESS</b>
<p>Records Found: " . $searchResponse->searchResult->totalRecords . "</p>
";
$i = 0;
$records = $searchResponse->searchResult->searchRowList->searchRow;
foreach ($records as $record) {
print "Item Name: " . $record->basic->itemId[0]->searchValue;print "<br/>";
print "Average Cost: " . $record->basic->averageCost[0]->searchValue;print "<br/><br/>";
}
}
}
No comments:
Post a Comment