> ## Documentation Index
> Fetch the complete documentation index at: https://docs.superoffice.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Typical search

> Details Find Selection Typical Search feature set.

Typical searches are predefined searches included with SuperOffice CRM. They provide a starting point when users create selections or filter data. A typical search copies its criteria into the user's working set, which the user can then edit without modifying the original definition.

## How typical searches work

Typical searches are stored as predefined selection templates. When the user chooses a typical search, its criteria replace the users current find criteria for the specified entity. If the user later decides to reset the criteria, they reset to the entity's default, not the typical search criteria that was copied.

## Updating typical searches

Typical searches are distributed as a JSON file stored in cloud storage. SuperOffice automatically updates the customer database when a newer version of the file is available. Updates may be triggered on a schedule or by manual requests from SuperOffice Operations Center.

## Data model

Typical searches use the same underlying search tables as other selection types, with an additional table that defines metadata for each typical search.

The 5 tables are:

* [SearchCriteria][1]
* [SearchCriteriaGroup][2]
* [SearchCriterion][3]
* [SearchCriterionValue][4]
* [TypicalSearch][5]

The TypicalSearch fields are:

| Name            | Data type |
| --------------- | --------- |
| Id              | int       |
| Title           | string    |
| Tooltip         | string    |
| IsEntityDefault | short     |
| IncludePerson   | short     |
| VersionNumber   | int       |
| Source          | string    |

A full list of the table fields can be found at the database reference.

Multi-language strings are used for the typical search title and tooltip to support all the different languages in SuperOffice.  The target entity field indicates which table the typical search is a selection of.

SearchCriteria contain `typicalsearch` in the name column, as well as the typical search ID (ownerId). A reference to the search provider is listed in the name field.

The name field consists of 3 parts: a search provider, the owner type (Selection, TypicalSearch, Associate) and an ID.

Example: `findproject selection=65`

A high-level description of how the criteria are stored:

* One top level anchor/owner (SelectionCriteria)
* A grouping of a set of criteria (SearchCriteriaGroup) which can be used to create "OR" groups.
* The type of criteria to use for filtering (SearchCriterion).
* The filtering value of the criteria (SearchCriterionValue) as in "one of..." or "equals..."

## Interface/API Definitions

### Import

`TypicalSearchesImplementation.UpdateTypicalSearches(TypicalSearches config)`

If the input parameter is null, it searches the file system to locate updated json files and import the data to the database. If the input parameter contains a `TypicalSearches` carrier, the contained data is imported.

### Find provider

`SuperOffice.Services.MDOListImplementation.GetList( string name, bool forceFlatList, string additionalInfo, bool onlyHistory)`

This method retrieves the typical search titles, tooltips and their related IDs for in the Find panel. The name parameter for the TypicalSearchProvider is TypicalSearch and additional info correspond to the entity name.

### Get Typical Search items

For each **entity** it's possible to obtain the list of corresponding typical search items.

<Tabs>
  <Tab title="REST">
    ```http theme={null}

    GET /api/v1/MDOList/typicalSearch/selectable?additional=contact HTTP/1.1
    Authorization: Bearer {access_token}
    Content-Type: application/json
    Accept: application/json
    Accept-Language: en
    ```
  </Tab>

  <Tab title="Agent">
    ```http theme={null}
    POST /api/v1/Agents/MDO/GetList HTTP/1.1
    Authorization: Bearer {access_token}
    Content-Type: application/json
    Accept: application/json

    {
      "Name": "typicalSearch",
      "ForceFlatList": true,
      "AdditionalInfo": "contact",
      "OnlyHistory": false
    }
    ```
  </Tab>

  <Tab title="WebApi Client">
    ```csharp theme={null}
    // setup access credentials
    var authorization = new AuthorizationAccessToken("{access_token}", OnlineEnvironment.SOD);
    var options = new WebApiOptions("https://sod.superoffice.com/Cust12345/api", authorization);

    // perform the request
    var mdoAgent = new MDOAgent(options);
    MDOListItem[] findEntities = await mdoAgent.GetListAsync("typicalSearch", true, "contact", false);
    ```
  </Tab>
</Tabs>

### Get archive provider for entity by typical search ID

Different typical search routines use different archive providers to perform the search. The following code demonstrates how to get the provider responsible for performing a typical search. There is no pure REST API to obtain this information. Use either the HTTP RPC Agent API or the WebApi client.

<Tabs>
  <Tab title="Agent">
    ```http theme={null}
    POST /api/v1/Agents/Selection/GetSelectionForFind HTTP/1.1
    Authorization: Bearer {access_token}
    Content-Type: application/json
    Accept: application/json

    {
      "EntityName": "contact",
      "TypicalSearchId": 2
    }
    ```
  </Tab>

  <Tab title="WebApi Client">
    ```csharp theme={null}
    // setup access credentials
    var authorization = new AuthorizationAccessToken("{access_token}", OnlineEnvironment.SOD);
    var options = new WebApiOptions("https://sod.superoffice.com/Cust12345/api", authorization);

    // perform the request
    var agent = new SelectionAgent(options);
    SelectionForFind selForFind = await agent.GetSelectionForFindAsync("contact", 2);
    ```
  </Tab>
</Tabs>

### Azure

SuperOffice.Services.TypicalSearchesImplementation.RequestLatestTypicalSearches(TypicalSearch optionalData)

Call this method to request an update to Azure Online for the typical searches.

**Continue reading:** [Details regarding export and import of typical search][6]

[1]: ../../../database/tables/searchcriteria

[2]: ../../../database/tables/searchcriteriagroup

[3]: ../../../database/tables/searchcriterion

[4]: ../../../database/tables/searchcriterionvalue

[5]: ../../../database/tables/typicalsearch

[6]: ./import-export-typical-search


## Related topics

- [NSTypicalSearch](/en/automation/crmscript/reference/CRMScript.NetServer.NSTypicalSearch.md)
- [NSTypicalSearches](/en/automation/crmscript/reference/CRMScript.NetServer.NSTypicalSearches.md)
- [Update Typical Search](/en/api/reference/restful/agent/selection_agent/update-typical-search.md)
- [Export and import of typical search](/en/api/search/find-selection/import-export-typical-search.md)
- [TypicalSearch table](/en/database/tables/typicalsearch.md)
- [SuperOffice.WebApi.Data.TypicalSearch](/en/api/reference/webapi/SuperOffice.WebApi.Data.TypicalSearch.md)
