Using Search Operations

Search operations support getting search data from either a saved query or through an ad-hoc approach. An ad-hoc search is not based on a existing saved search. You can specify filters, columns, general search, and sorting capabilities. At a minimum, you must specify the Business Object ID.

Usage: Filters

To specify filtering, use the Filters member in the SearchResultsRequest. The Filters member is a collection of FilterInfo data structures. A FilterInfo contains the full field ID, operator and value.

You can specify more than one filter. If you add multiple filters for the same field ID, the result is an OR operation between those filters. If the field IDs are different, the result is an AND operation between those filters.

The following table shows the supported operators.

eq Equals specified value
gt Greater than specified value
lt Less than specified value
contains Contains specified value
startswith Starts with specified value

The following example shows how to specify a filter on the Incident ID field to find a specific incident.

Copy
ApiTrebuchetWebApiDataContractsSearchesSearchResultsRequest searchResults = new ApiTrebuchetWebApiDataContractsSearchesSearchResultsRequest();
searchResults.BusObId = "6dd53665c0c24cab86870a21cf6434ae";
 
// Create a filter on the incident ID field
searchResults.Filters = new System.Collections.Generic.List<ApiTrebuchetWebApiDataContractsSearchesFilterInfo>();
 
ApiTrebuchetWebApiDataContractsSearchesFilterInfo filter1 = new ApiTrebuchetWebApiDataContractsSearchesFilterInfo();
filter1.FieldId = "BO:6dd53665c0c24cab86870a21cf6434ae,FI:6ae282c55e8e4266ae66ffc070c17fa3";
filter1.Operator = "eq";
filter1.Value = "100216";                        
searchResults.Filters.Add(filter1);
 
SearchesApi searches = new SearchesApi(apiClient);
ApiTrebuchetWebApiDataContractsSearchesSearchResultsResponse response = searches.SearchesGetSearchResultsAdHocV1(searchResults);

In the following example, there are two filters for the incident ID field. This means that any incidents with IncidentID = 100216 OR IncidentID=200367 will be found.

Copy
ApiTrebuchetWebApiDataContractsSearchesSearchResultsRequest searchResults = new ApiTrebuchetWebApiDataContractsSearchesSearchResultsRequest();
searchResults.BusObId = "6dd53665c0c24cab86870a21cf6434ae";
 
// Create a filter on the incident ID field
searchResults.Filters = new System.Collections.Generic.List<ApiTrebuchetWebApiDataContractsSearchesFilterInfo>();
 
ApiTrebuchetWebApiDataContractsSearchesFilterInfo filter1 = new ApiTrebuchetWebApiDataContractsSearchesFilterInfo();
filter1.FieldId = "BO:6dd53665c0c24cab86870a21cf6434ae,FI:6ae282c55e8e4266ae66ffc070c17fa3";
filter1.Operator = "eq";
filter1.Value = "100216";                        
searchResults.Filters.Add(filter1);
 
ApiTrebuchetWebApiDataContractsSearchesFilterInfo filter2 = new ApiTrebuchetWebApiDataContractsSearchesFilterInfo();
filter2.FieldId = "BO:6dd53665c0c24cab86870a21cf6434ae,FI:6ae282c55e8e4266ae66ffc070c17fa3";
filter2.Operator = "eq";
filter2.Value = "200367";
searchResults.Filters.Add(filter2);

// Query for data
SearchesApi searches = new SearchesApi(apiClient);
ApiTrebuchetWebApiDataContractsSearchesSearchResultsResponse response = searches.SearchesGetSearchResultsAdHocV1(searchResults);    

Usage: Fields

By default, if you do not specify fields, a default set of fields (defined by the default Grid definition for the Business Object) is used to determine which fields will be displayed. You can override this behavior and specify the fields to include in your results. Use the Fields collection and add the full IDs of the fields to include:

Copy
ApiTrebuchetWebApiDataContractsSearchesSearchResultsRequest searchResults = new ApiTrebuchetWebApiDataContractsSearchesSearchResultsRequest();
searchResults.BusObId = "6dd53665c0c24cab86870a21cf6434ae";
 
searchResults.Fields= new System.Collections.Generic.List<string>();
searchResults.Fields.Add("BO:6dd53665c0c24cab86870a21cf6434ae,FI:6ae282c55e8e4266ae66ffc070c17fa3");

Usage: Search Results Field Templates

Use POST api/V1/getsearchresultsbusinessobjects to use the powerful filtering, sorting, and field specification abilities of the search results API to produce results that are in the field template data structure syntax (see Business Objects / Field Templates).

You can then update values within that set of field template and then update those records. There are several scenarios where this might be useful. For example, you can find all incidents older than 1 year, and then set their status to closed.

Examples