简体   繁体   中英

Search NetSuite Custom Record Type in PHP

I have a Custom Record Type and I am having trouble searching the barcode from the item value:

在此处输入图像描述

I am using the NetSuite PHPToolkit_2015_2 and this stackoverflow answer https://stackoverflow.com/a/13366947/2120512 and http://burnignorance.com/netsuite-tips-and-hacks/working-with-custom-records-in-suitetalk/ to attempt to build this request:

$service = new NetSuiteService();
// Perform an AdvancedSearch for Items
// https://netsuite.custhelp.com/app/answers/detail/a_id/12203/kw/php%20search%20criteria

$service->setSearchPreferences(false, 1000, false);
$savedSearchId = 'customsearch_barcode_view'; //customsearch## from UI ID field
$searchAdvanced = new CustomRecordSearchAdvanced();
setFields($searchAdvanced, array('savedSearchScriptId'=>$savedSearchId));

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

// PHP Toolkit 2012.2: Sample Code to Perform Search that Uses a Custom Field as Filter
// https://netsuite.custhelp.com/app/answers/detail/a_id/25066/kw/php%20custom%20field

$custSearchField = new SearchMultiSelectCustomField();
$custSearchField->value = new ListOrRecordRef();
$custSearchField->value->internalId = "custrecord_barcode_item";
$custSearchField->value->value = "00001 Beer Mug";

$searchAdvanced->customFieldList = $custSearchField;

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

I still get all the results for the Custom Record Type and never able to figure out how to search by the item. I have made changes and still receive the entire results.

I'm pretty sure this won't immediately solve your problem, but at the first glance I can see an error in your code.

The customFieldList is of type array, so you need to change this:

$searchAdvanced->customFieldList = $custSearchField;

To this

$searchAdvanced->customFieldList = [$custSearchField];

Were you ever able to solve this problem? I am experiencing the same thing. I am trying to use a saved search but filter by a custom field. I am always getting all results from the saved search.

 public function lookupNetSuitSubscriptionByWCID($wcId = null) {
    if (!$wcId) return 0;

    $this->nsProvider->setSearchPreferences(false, 10, false);

    // search custom field - woocommerce id
    $searchCustomFields = array();
    $wcIdField = new SearchStringCustomField;
    $wcIdField->scriptId = 'custrecord_mtd_sub_id';
    $wcIdField->searchValue = $wcId;
    $wcIdField->operator = SearchStringFieldOperator::is;
    $searchCustomFields[] = $wcIdField;

    $search = new CustomRecordSearchAdvanced();
    $search->savedSearchId = "3353"; // MTD Subscriptions Saved Search

    $search->customFieldList = new SearchCustomFieldList();
    $search->customFieldList->customField = $searchCustomFields;

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

    $searchResponse = $this->nsProvider->search($request);
    return $searchResponse;

    $result = 0;
    if (
        ($searchResponse->searchResult->status->isSuccess) &&
        ($searchResponse->searchResult->totalRecords > 0) &&
        (!empty($searchResponse->searchResult->recordList->record[0]))
    ) {
        $result = $searchResponse->searchResult->recordList->record[0]->internalId;
    }
    return $result;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM