使用Netsuite php工具包搜索客户过滤的销售订单

时间:2016-09-06 10:10:32

标签: php web-services netsuite

我需要搜索特定客户的所有销售订单(使用客户内部ID或实体ID)。当我在脚本下面运行时,它会返回所有销售订单(页面为20)。如何过滤客户的结果?

require_once 'PHPToolkit/NetSuiteService.php';

$service = new NetSuiteService();


    $service->setSearchPreferences(false, 20);

    $SearchEnumMultiSelectField = new SearchEnumMultiSelectField();
    $SearchEnumMultiSelectField->searchValue = Array('_salesOrder');
    $SearchEnumMultiSelectField->operator = 'anyOf';

    $search = new TransactionSearchBasic();
    $search->type = $SearchEnumMultiSelectField;

    //$search->customForm = new SearchMultiSelectField();
    //$id = new RecordRef();
    //$id->internalId = 'xxxxxx';  customer internal Id
    //$search->customForm->searchValue = $id;


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

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

    echo print_r($searchResponse,true);

1 个答案:

答案 0 :(得分:0)

        $service = new NetSuiteService(self::_config);
        $customerSearchBasic = new CustomerSearchBasic();

        $searchValue = new RecordRef();
        $searchValue->type = 'customer';
        $searchValue->internalId = $customer_id;

        $searchMultiSelectField = new SearchMultiSelectField();
        setFields($searchMultiSelectField, array('operator' => 'anyOf', 'searchValue' => $searchValue));
        $customerSearchBasic->internalId = $searchMultiSelectField;

        $transactionSearchBasic = new TransactionSearchBasic();

        $searchMultiSelectEnumField = new SearchEnumMultiSelectField();
        setFields($searchMultiSelectEnumField, array('operator' => 'anyOf', 'searchValue' => "_salesOrder"));

        $transactionSearchBasic->type = $searchMultiSelectEnumField;
        $transactionSearch = new TransactionSearch();
        $transactionSearch->basic = $transactionSearchBasic;
        $transactionSearch->customerJoin = $customerSearchBasic;

        $request = new SearchRequest();
        $request->searchRecord = $transactionSearch;
        $searchResponse = $service->search($request);

        if ($searchResponse->searchResult->status->isSuccess) {
            if(isset($searchResponse->searchResult->recordList)) {
                return $searchResponse->searchResult->recordList->record;
            }
        }