2012-07-02 40 views
0

我想從Netsuite的某個倉庫返回所有庫存。我有一些問題,並想知道是否有人可以指出我正確的方向。我試圖查詢的倉庫的internalId是16.當我執行搜索時,它返回0個項目 - 但不會失敗。Netsuite PHP ItemSearch基本問題

這是我正在使用的PHP代碼。

<?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(); 
} 

這裏是SOAP請求

<?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> 

回答

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

然後,做你的try/catch。

但是,當我看着這個,你想要獲得物品的可用性。這是完全不同的呼叫。

$filter = new nsComplexObject ('ItemAvailabilityFilter'); 
$filter->setFields (array (
    "location" => array (
     "operator" => "anyOf", 
     "searchValue" => new nsRecordRef (array (
      "type" => "location", 
      "internalId" => $internalId 
     )) 
    ) 
)); 
0

我花的時間建立使用PHPToolKit v2011.2端點自己的自定義搜索顯著量,並得到了他們的,因爲沒有那麼多的例子出來拉我的頭髮後,開始工作。隨着v2012_2端點的引入,情況發生了變化,我必須重新學習我之前解決的問題。我「強烈地」建議你使用SAVED SEARCH,而不是試圖發明在PHP中進行所有搜索的方式。在Netsuite中創建一個保存的搜索,並用您創建的搜索的internalId從PHP中調用SAVED SEARCH。