Sunday, September 9, 2018

Web Service > PHPToolkit > Perform an AdvancedSearch for Items

Note: This article requires existing knowledge of Web Services and PHP.

Note: This article applies to the PHP Toolkit before version 2012.2.

As per the Suite Talk Web Services Platform Guide; Advanced searches in Web Services provides users with the ability to perform a search that references an existing saved search.

This Article outlines a sample for performing and Advanced Search using the PHPToolkit that performs an ItemSearchAdvanced using a UI Item search with customsearch##, and adds the criteria for a specific item 'category'


...
require_once '../../PHPtoolkit.php';
require_once '../login_info.php';

global $myNSclient;

$myNSclient->setSearchPreferences(false, 20); $savedSearchId = 'customsearch##'; //customsearch## from UI ID field
$searchAdvanced = new nsComplexObject('ItemSearchAdvanced');
$searchAdvanced->setFields(array('savedSearchScriptId'=>$savedSearchId));
$search = new nsComplexObject('ItemSearch');

//Start code to add additional criteria using product category as a field.

$myResponderRefRecord = new nsRecordRef(array('internalId' => '#')); //Where # is the internalID of the product category
$multiselectfield = new nsComplexObject('SearchMultiSelectField');
$multiselectfield->setFields(array('operator'=>'anyOf','searchValue'=>$myResponderRefRecord));
$itemsearchobject = new nsComplexObject('ItemSearchBasic');
$itemsearchobject->setFields(array('category'=>$multiselectfield));
$search->setFields(array('basic'=>$itemsearchobject));
$searchAdvanced->setFields(array('criteria'=>$search));

//End code to add additional criteria

$results = $myNSclient->search($searchAdvanced);
print_r($results);//dumps the results directly from PHPToolkit
...


The above code would generate the following SOAP request:

<body>
  <search>
    <searchRecord savedSearchScriptId="customsearch##" type="ItemSearchAdvanced">
      <criteria>
        <basic>
          <category operator="anyOf">
            <searchValue internalId="#" />
          </category>
        </basic>
      </criteria>
   </searchRecord>
  </search>
</body>
 



 

No comments:

Post a Comment