Sunday, March 10, 2019

PHP Toolkit 2012.2 > ItemSearchAdvanced Sample Code

This provides a sample code to make an ItemSearchAdvanced request using PHPToolkit 2012.2.  The article requires a basic understanding of PHP and Web Services to get this working.

The following example searches for an Item record, using internalIdNumber as filter.

     <?php

     require_once './PHPToolkit/NetSuiteService.php';

     set_time_limit(0);

     $service = new NetSuiteService();
     $service->setPreferences(false, false, false, true);
     $service->setSearchPreferences(true);

     // internalIdNumber Criteria
     $intIdNumCriteria = new SearchLongField();
     $intIdNumCriteria->operator = SearchLongFieldOperator::equalTo;
     $intIdNumCriteria->searchValue = '777';

     $itemSearchBasic = new ItemSearchBasic();
     $itemSearchBasic->internalIdNumber = $intIdNumCriteria;

     $itemSearch = new ItemSearch();
     $itemSearch->basic = $itemSearchBasic;

     $itemRowBasic = new ItemSearchRowBasic();
     $itemRowBasic->itemId = new SearchColumnStringField();
     $itemRowBasic->internalId = new SearchColumnSelectField();

     $itemSearchRow = new ItemSearchRow();
     $itemSearchRow->basic = $itemRowBasic;

     $itemSearchAdvanced = new ItemSearchAdvanced();
     $itemSearchAdvanced->criteria = $itemSearch;
     $itemSearchAdvanced->columns = $itemSearchRow;

     $request = new SearchRequest();
     $request->searchRecord = $itemSearchAdvanced;

     $searchResponse = $service->search($request);

The above codes produce a search SOAP request like the one below

     <SOAP-ENV:Body>
          <ns4:search>
               <ns4:searchRecord xsi:type="ns3:ItemSearchAdvanced">
                    <ns3:criteria>
                         <ns3:basic>
                              <ns2:internalIdNumber operator="equalTo">
                                   <ns1:searchValue>277</ns1:searchValue> 
                              </ns2:internalIdNumber>
                         </ns3:basic>
                    </ns3:criteria>
                    <ns3:columns>
                         <ns3:basic>
                              <ns2:internalId /> 
                              <ns2:itemId /> 
                         </ns3:basic>
                    </ns3:columns>
               </ns4:searchRecord>
          </ns4:search>
     </SOAP-ENV:Body>

No comments:

Post a Comment