Netsuite Webservices and Saved Searches

Marianne Mason was kind enough to send me the following code example. It preforms a saved search and returns the results using the Netsuite PHPToolkit. If you are looking for a simple search or want to see the full discussion, see the earlier post.

require_once ‘PHPtoolkit.php’;
require_once ‘login_info.php’;
global $myNSClient;

$id = ‘saved search ID’;
$item = new nsComplexObject(‘SearchStringField’);
$item->setFields(array( ‘searchValue’ => $id,
‘operator’ => ‘is’));
$searchItem = array (
‘savedSearchScriptId’ => $item
);

//object type would be replaced with the correct type
$search = new nsComplexObject(‘TransactionSearchAdvanced’);
$search->setFields($searchItem );

//from this point down, this is your code

$myNSclient->setSearchPreferences(false, 10);
try {
$response = $myNSclient->search($search);
}
This entry was posted in Beginning with the PHPToolkit, Netsuite PHPToolkit and tagged , , , , , , . Bookmark the permalink.

12 Responses to Netsuite Webservices and Saved Searches

  1. Bigjoy says:

    Thanks for the code. The saved search response returns only the internal id for the lists like the customer status. While viewing the saved search results the customer status field show the actual value(e.g ‘Customer Close-Won’) but the response only sends back the internal id. Do i need to put in another request to get the value of the status or is there any setting in the saved search interface that would allow me to get the value instead of the internal id.

    Appreciate your help.

    • ReefaDT says:

      I’m having the same issue — Custom Fields in Saved Searches come back as their Internal ID, not their value. Did you find a way to make a saved search return the value of the custom field rather than the internal id?

  2. dacey says:

    Thanks for the information its very helpful searching related to net suite.I was looking for this code from such a long time but didn’t get it any where thanks for the post and code

  3. jose mera says:

    I tried the example above and could not get it to work (the search results were not what my saved search returns). Then I changed lines 6 through 10 (see bellow) and I got it to work :

    $id = ‘saved search ID’;
    $searchItem = array(‘savedSearchScriptId’ => $id);

    //object type would be replaced with the correct type
    $search = new nsComplexObject(‘TransactionSearchAdvanced’);
    $search->setFields($searchItem);

    //from this point down, this is your code
    $myNSclient->setSearchPreferences(false, 10);
    try {
    $response = $myNSclient->search($search);
    } catch(Exception $e){
    //do something
    }

  4. chris ronk says:

    hello, I am trying to create a script that will create a new lead in Netsuite from an external website. What I am missing is the login_info.php that your script is calling.

    I am not a programmer and I do not know the syntax for that script. Is it possible to send me your login_info.php (with the personal info removed of course)?

    Thanks

  5. Joe Motacek says:

    Thanks for all the great work guys. Your references have been an irreplaceable resource in a project I am working on. I’m working on a Joomla component that connects to NetSuite and I have gotten stumped today. Here is what I’m trying to do:

    $orderSearch = new nsComplexObject(‘TransactionSearchBasic’);

    $orderSearch->setFields(array(
    “nameText” => array(
    “operator” => “is”,
    “searchValue” => $this->customerName
    ),
    “type” => array(
    “operator” => “is”,
    “serachValue” => “Sales Order”
    )
    ));

    Problem of course is that “type” is a SearchEnumMultiSelectFieldOperator and I haven’t found a good example on how these are set in a search of any kind so I am unsure of the sytax. (Or maybe I have but didn’t recognize it) I’m not sure if you guys have tried to use these or not but if you have any ideas I’d appreciate it.

    Thanks
    -Moto

    • Joe Motacek says:

      I found the answer finally if anyone else is interested:

      $orderSearch = new nsComplexObject(‘TransactionSearchBasic’);

      $typeSearchField = new nsComplexObject(‘SearchEnumMultiSelectField’);
      $typeSearchField->setFields(array(‘searchValue’ => array(‘_salesOrder’),
      ‘operator’ => ‘anyOf’));

      $orderSearch->setFields(array(
      “nameText” => array(
      “operator” => “is”,
      “searchValue” => $this->customerName
      ),
      “type”=>$typeSearchField
      ));

  6. richiewilko says:

    Thanks for the info.

    For reference jose mera script worked for me but I want to highlight the importance of getting the correct object type.

    I was getting an error ‘INVALID_SAVEDSEARCH A saved search with the internal ID xxx does not exist.’

    I was running a Item search using the TransactionSearchAdvanced which is wrong. Make sure you match up the objects correctly.

    Also I’m using
    $searchItem = array(‘savedSearchId’ => $id);
    instead of
    $searchItem = array(‘savedSearchScriptId’ => $id);
    which works better for me.

  7. Jeremy says:

    I was able to get the saved search working in a different way. The saved search id is the internal id of the search. Here is my sample code:

    require_once ‘../PHPToolkit/NetSuiteService.php’;

    $service = new NetSuiteService();
    $search = new CustomerSearchAdvanced();
    $search->savedSearchId = “1001″;

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

    if (!$searchResponse->searchResult->status->isSuccess) {
    echo “SEARCH ERROR”;
    } else {
    echo “SEARCH SUCCESS, records found: ” . $searchResponse->searchResult->totalRecords . “\n”;
    $records = $searchResponse->searchResult->searchRowList->searchRow;

    foreach ($records as $record) {
    echo “email: ” . $record->basic->email[0]->searchValue . “\n”;
    echo “First: ” . $record->basic->firstName[0]->searchValue . “\n”;
    echo “Last: ” . $record->basic->lastName[0]->searchValue . “\n\n”;
    echo “Phone: ” . $record->basic->phone[0]->searchValue . “\n\n”;
    }
    }

  8. Manoj says:

    I have the saved search workign fine with the following code, but I want to get the data between two tranDates
    Can anyone help in that?

    require_once ‘PHPToolkit/NetSuiteService.php’;
    $service = new NetSuiteService();
    $search = new TransactionSearchAdvanced();
    $search->savedSearchId = “810″;

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

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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>