Question

I have a saved search in Netsuite that's only criteria is "Type is Item Group" and I am trying to use the Soap API SuiteTalk to retrieve its results through PHP.

Here's the function I'm using:

function getSavedSearch($ns_client, $search_id, $search_type, $page_size = 1000) {
    $searchItem = array();
    $searchItem['savedSearchId'] = $search_id;

    $search = new nsComplexObject($search_type);
    $search->setFields($searchItem);

    $ns_client->setSearchPreferences(false, $page_size);
    return $ns_client->search($search);
}

I try calling it with the search's internalId and the type 'ItemSearchAdvanced' but that returns a search with 0 records.

If I change the type to 'ItemSearchBasic' it seems to ignore the search criteria and I get every item record in the system (not limited to item groups).

I am able to use the same function to retrieve the results of other saved searches such as as "Transaction Search" using the type "TransactionSearchAdvanced".

I suspect there is a different search type I should be using but I can't find any references to what it should be.

Was it helpful?

Solution

This code uses an older version of the Toolkit.

The 2013_1 version is much, much better and easier to use. Also, be careful which endpoint the Toolkit points toward, as older versions, like 2009_2 are no longer supported.

The code when using the 2013_1 version of the Toolkit is simple:

$service = new NetSuiteService();
$search = new ItemSearchAdvanced();
$search->savedSearchId = "XX"; //replace with your internal ID 

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

$searchResponse = $service->search($request);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top