0

I am trying to return all inventory from a certain warehouse in Netsuite. I am having some issues and was wondering if anyone could point me in the right direction. The internalId of the warehouse I am trying to query is 16. When I do the search it returns 0 items - but doesn't fail.

Here is the PHP code I am working with.

<?php
require_once 'PHPtoolkit.php';
require_once 'login_info.php';
global $myNSclient;


$internalID = '16'; //Internal ID of the warehouse I want to query to see what inventory it has

$inventorySearch = new nsComplexObject("ItemSearchBasic");

$searchValue = new nsRecordRef(array('type' => 'location', 'internalId' => $internalID ));

$multiSelect = new nsComplexObject('SearchMultiSelectField');
$multiSelect->setFields(array('operator'=>'anyOf','searchValue'=>$searchValue,"operatorSpecified" => true));


$inventorySearch->setFields(array('location'=>$multiSelect));

try
{
    $searchResponse = $myNSclient->search($inventorySearch);
    $totalRecords = $searchResponse->totalRecords;
    if ($totalRecords > 0)
    {
        echo "records found";
        foreach ($searchResponse->recordList as $record)
        {
            echo "<pre>";
            print_r($record);
            echo "</pre>";
        }
    }
    else
    {
        echo "No result found.";
    }

}
catch (Exception $e)
{
    echo $e;
    echo "Item is not found. Please try again.";
    exit();
}

Here is the SOAP request

  <?xml version="1.0" encoding="UTF-8" ?> 
- <Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:core_2011_2.platform.webservices.netsuite.com" xmlns:ns2="urn:common_2011_2.platform.webservices.netsuite.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns3="urn:messages_2011_2.platform.webservices.netsuite.com">
- <Header>
- <passport actor="http://schemas.xmlsoap.org/soap/actor/next">
  <email>xxxxx</email> 
  <password>[Content Removed for Security Reasons]</password> 
  <account>xxxxxx</account> 
  <role internalId="3" xsi:type="RecordRef" /> 
  </passport>
  </Header>
- <Bod
y>
- <search>
- <searchRecord xsi:type="ItemSearchBasic">
- <location operator="anyOf">
  <searchValue internalId="16" type="location" /> 
  </location>
  </searchRecord>
  </search>
  </Body>
  </Envelope>
lodkkx
  • 1,163
  • 2
  • 17
  • 29

2 Answers2

3
$inventorySearch = new nsComplexObject("ItemSearchBasic"); 
$inventorySearch->setFields(array(
    "location" => array(
        "operator" => "anyOf",
        "searchValue" => array(
            "type" => "location",
            "internalId" => $internalId
        )
     )
));

Then, do your try/catch.

But as I look at this, you are wanting to get item availability. That's a completely different call.

$filter = new nsComplexObject ( 'ItemAvailabilityFilter' );
$filter->setFields ( array (
    "location" => array (
        "operator" => "anyOf",
        "searchValue" => new nsRecordRef ( array (
            "type" => "location",
            "internalId" => $internalId 
        ) ) 
    ) 
) );
Hausen Zheng
  • 204
  • 1
  • 7
Dave Weiss
  • 31
  • 2
1

I've spent significant amount of time building my own custom search using PHPToolKit v2011.2 endpoint, and got them to work after pulling my hair out as there aren't that many examples. With introduction of v2012_2 endpoint, things have changed and I have to relearn the things that I solved before. I "strongly" suggest that you use SAVED SEARCH, instead of trying to invent the way to do all your searches in PHP. Create a saved search in Netsuite, and call the SAVED SEARCH from your PHP with internalId of the search you created.

aladar
  • 61
  • 1
  • 3