Thursday, September 20, 2018

Customer is reporting an error on PHPToolkit when he invokes a search without having any criteria

Customer wants to pull up all his records under a certain record type. He needs to invoke a search operation in Web Service to do it. He does not need to specify any criteria so that all records will be pulled up. But when he do this using PHPToolkit, it gives him an error.
 
Sample Code snippet:
 
$itemSearch = new nsComplexObject('ItemSearchBasic');
 
$myNSclient->setSearchPreferences(false, 100);
 
$searchResponse = $myNSclient->search($itemSearch);
if ($searchResponse->isSuccess) { 
 echo "<h1>Search Successful</h1>"; 
}
 

 
This code will result to:
 
Fatal error: Uncaught SoapFault exception: [soapenv:Server.userException] org.xml.sax.SAXException:
 
It is still not possible for PHPToolkit to have a search without any specified criteria. The workaround will be to include one field which is mandatory for the record/s and set the operator to isnotempty.
 
Sample Code Snippet:
 
$itemSearch = new nsComplexObject('ItemSearchBasic');
$itemId = new nsComplexObject('SearchStringField');
$itemId->setFields(array('operator' => 'isnotempty'));
 
$myNSclient->setSearchPreferences(false, 100);
 
$itemSearchFields = array ('itemid' => $itemId);
 
$itemSearch->setFields($itemSearchFields);
 
$searchResponse = $myNSclient->search($itemSearch);
 
if ($searchResponse->isSuccess) {
 echo "<h1>Search Successful</h1>"; 
}

No comments:

Post a Comment