Advanced Searches in SOAP Web Services

Advanced searching in SOAP web services provides users with the ability to:

The SOAP web services API includes advanced search objects for all records that have an existing search interface. To see which objects are used to execute advanced searches, see SOAP Objects used in Advanced Searches

For advanced search code samples, see Advanced Search Code Samples.

In case you encounter duplicate or missing search results, ensure your search references an existing saved search in which the results are sorted by Internal ID. For more information about defining the sorting of the results, see Defining a Saved Search.

The following is an XSD snippet of the listRel XSD. This sample provides a high-level overview of advanced search objects and their relationship to the basic search object < Record > Search. In this sample, the objects Customer SearchAdvanced, Customer SearchRow, and Customer SearchRowBasic (not shown in sample) are considered to be advanced search objects in the SOAP web services API.

An overview of advanced search objects.
Note:

For additional SOAP and code samples related to searches, see Search-Related Sample Code, Joining Through Custom Fields, and Searches.

Reference Existing Saved Searches

Advanced search in SOAP web services lets you reference an existing saved search. Returning saved searches provides you with access to data that otherwise could not be returned in SOAP web services. For example, advanced search lets you return saved searches that include formula filters (in the search criteria) or expressions.

When working with saved searches, two questions come to mind for SOAP web services users:

Reasons to Reference an Existing Saved Search

The following use cases illustrate possible scenarios for referencing a saved search:

How to Reference an Existing Saved Search

First you must obtain the saved search ID. You can do so through the UI by going to Lists > Search > Saved Searches. The saved search ID appears in the ID column.

You can also use the getSavedSearch operation to programmatically retrieve a list of saved search IDs for a specific record type. Note that this operation does nothing more than return a list of saved search IDs on a per-record-type basis (for example, all saved search IDs for the customer record type).

You can then use the search() operation, along with the < Record > SearchAdvanced object to return the details of the saved search. The following is a example that shows how to instantiate the CustomerSearchAdvanced object and specify a savedSearchId to return.

          // create search object
CustomerSearchAdvanced customerSearch = new CustomerSearchAdvanced();
 
//set saved search id
customerSearch.savedSearchId="100";
 
// perform the search
NetSuiteService nss = new NetSuiteService(); 
SearchResult result = nss.search(customerSearch); 

        

For more detailed samples, see Advanced Search Code Samples.

Usage Notes

Specify Search Criteria and Search Return Columns

Similar to a basic search, an advanced search allows you search against a specific record type using the fields on that record as search filters. In addition, you can also specify a set of search return columns or joined columns to return.

This kind of advanced search is useful for retrieving only the record data you need rather than the contents of an entire record.

Advanced searches work well, for example, for users who may have a mobile client that needs to display only the name, phone number, and email address of their sales rep contact. Rather than returning all of the data on a contact record, users can create an advanced search that pulls only the relevant information. They are no longer required to download the entire record.

For advanced search code samples that show how to specify both search criteria and search return columns, see Advanced Search Code Samples.

Search Return Columns

The following figures show the UI equivalent of an advanced search that includes search return columns.

  1. First, specify the basic search criteria on the Criteria subtab (in this example all customers that have a company name starting with the letter A).

    An advanced search that includes search return columns.
  2. Next, click the Results subtab to define the search return columns. When your search is executed, your search response will return only the company name, phone, and contact name of all customers whose company starts with the letter A.

    The results tab of a search in the UI.

The following figure shows the results of the search. Only the relevant data are returned.

The results of a search in the UI.

SOAP Objects used in Advanced Searches

The following summarizes the objects used in different types of advanced searches. For additional details, see Advanced Search Objects Explained and Advanced Search Code Samples.

Advanced Search Objects Explained

The < Record >SearchAdvanced object contains:

Note:

If the Show Internal ID preference is enabled in your NetSuite account, the saved search internal ID appears in the Internal ID column in a saved search list. Programmatically, you can use getSavedSearch to obtain a list of saved search internal IDs for a specific record type.

Note:

If the Show Internal ID preference is enabled in your NetSuite account, the saved search ID appears in the ID column in a saved search list.

Important:

You cannot use getSavedSearch to return a list of custom saved search IDs; only the system-defined internal IDs (57, 99, 63, etc.) will be returned.

The XSD sample below shows the CustomerSearchAdvanced object:

          <complexType name=" CustomerSearchAdvanced ">
   <complexContent>
      <extension base="platformCore:SearchRecord">
         <sequence>
            <element name=" criteria " type="listRel:CustomerSearch" minOccurs="0"/>
            <element name=" columns " type="listRel:CustomerSearchRow" minOccurs="0"/>
            </sequence>
            <attribute name=" savedSearchId " type="xsd:string"/>
            <attribute name=" savedSearchScriptId " type="xsd:string"/>
         </extension> 

        

The < Record >SearchRow object contains:

The XSD below shows a snippet of the CustomerSearchRow object:

          <complexType name=" CustomerSearchRow ">
   <complexContent>
      <extension base="platformCore:SearchRow">
           <sequence>
             <element name=" basic " type="platformCommon:CustomerSearchRowBasic"
               minOccurs="0"/>
             <element name=" callJoin " type="platformCommon:PhoneCallSearchRowBasic"
            minOccurs="0"/>
             <element name=" campaignResponseJoin "type="platformCommon:CampaignSearchRowBasic"
            minOccurs="0"/>
         <element name=" caseJoin " type="platformCommon:SupportCaseSearchRowBasic"
            minOccurs="0"/>
            ......
          </sequence>
      </extension>
   </complexContent>
</complexType> 

        

The < Record >SearchRowBasic object contains:

The next snippet shows the CustomerSearchRowBasic object, which, like ALL < Record > SearchRowBasic objects, resides in the platformCommon XSD. This object lists all available search return columns for the Customer record.

          <complexType name=" CustomerSearchRowBasic ">
        <sequence>
            <element name=" accountNumber " type="platformCore: SearchColumnStringField " minOccurs="0"
      maxOccurs="unbounded"/>
            <element name=" address " type="platformCore: SearchColumnStringField " minOccurs="0"
      maxOccurs="unbounded"/>
            <element name=" addressee " type="platformCore: SearchColumnStringField " minOccurs="0"
      maxOccurs="unbounded"/>
            <element name=" addressLabel " type="platformCore: SearchColumnStringField " minOccurs="0"
      maxOccurs="unbounded"/>
           ...

        </sequence>
    </complexType> 

        

Note that all search return columns reference SearchColumn< xxx >Field objects. See Search Column Custom XML Schema Types for definitions of each search column object.

Important:

When executing an advanced search, you can set the SearchPreferences. returnSearchColumns preference to TRUE to ensure that only search return columns are returned in a search. An error is thrown if returnSearchColumns is set to TRUE and you have not specified search return columns in your request. (Note that you will not receive an error if you are using advanced search functionality to return a saved search that already includes search return columns.)

Note:

Also note that in an advanced search, the bodyFieldsOnly preference is ignored.

The default value for returnSearchColumns is TRUE.

           <complexType name="SearchPreferences">
 <sequence>
  <element name="bodyFieldsOnly" minOccurs="0" type="xsd:boolean" default="true"/>
  <element name=" returnSearchColumns " minOccurs="0" type="xsd:boolean"
      default="true"/>
  <element name="pageSize" minOccurs="0" type="xsd:int"/>
 </sequence>
</complexType> 

        

Related Topics

General Notices