> ## 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.

# Dynamic selections

> Dynamic selection

The structure of a dynamic selection is defined by several tables that contain the criteria definitions. This structure is complex and easy to get wrong. We strongly urge you to use the COM objects or the NetServer APIs to create and modify the criteria instead of doing it directly.

![Dynamic selection -screenshot][img1]

The corresponding Selection table row looks like this:

| selection\_id | associate\_id | group\_idx | name                | text\_id | visibility | seltype | ... |
| ------------- | ------------- | ---------- | ------------------- | -------- | ---------- | ------- | --- |
| 76            | 13            | 1          | A Dynamic Selection | 0        | 1          | 1       |     |

<Note>
  The selType = 1 (dynamic)
</Note>

The actual criteria are stored in the `searchCriteria` table:

```SQL theme={null}
SELECT * FROM searchcriteria WHERE ownertable=23 and ownerid=76
```

| SearchCriteria\_id | name | textId | ownerType | ownerTable | ownerId | registered          | registered\_associate\_id |
| ------------------ | ---- | ------ | --------- | ---------- | ------- | ------------------- | ------------------------- |
| 24                 |      | 0      | 1         | 23         | 76      | 01.12.2020 17:33:01 | 13                        |

This criterion contains one criteria group (the group concept is there to support more complex searches using AND/OR operators and so on - nothing is implemented yet though).

```SQL theme={null}
SELECT * FROM searchcriteriagroup WHERE searchcriteria_id = 24
```

| SearchCriteriaGroup\_id | SearchCriteria\_id | name     | textId | direction | rank | registered          | registered\_associate\_id |
| ----------------------- | ------------------ | -------- | ------ | --------- | ---- | ------------------- | ------------------------- |
| 20                      | 24                 | Group: 0 | 0      | 1         | 0    | 01.12.2020 17:33:01 | 13                        |

The group contains one or more search criterion records: each criterion corresponds to a field.

```SQL theme={null}
SELECT * FROM searchcriterion WHERE searchcriteriagroup_id = 20
```

| SearchCriterion\_id | SearchCriteriaGroup\_id | criterionId | extraId | operatorId | linkType | ... |
| ------------------- | ----------------------- | ----------- | ------- | ---------- | -------- | --- |
| 24                  | 20                      | 1281        | 0       | 18         | 0        |     |

<Note>
  The [contact.name][1] field (1281) is stored in the `criterionI`. The `extraId` is used when referencing the [SAINT counters][2].
</Note>

Operator 18 = Begins with

The actual value that we want to search for is stored in a separate table so that we can support multiple values per search criterion (for the is-one-of searches).

```SQL theme={null}
SELECT * FROM searchcriterionvalue WHERE searchCriterion_id = 24
```

| SearchCriterionValue\_id | SearchCriterion\_id | stringValue | rank | listTableId | listItemId | ... |
| ------------------------ | ------------------- | ----------- | ---- | ----------- | ---------- | --- |
| 52                       | 24                  | Super       | 0    | 242         | 0          |     |

Which of the fields you need to fill in depends on the field used in the `criterionId`. `Contact.Name` is a string value, so the `stringValue` field in the `criterionValue` should be filled out.

## Find dialog

The search criteria tables are also used when defining extra fields in the **Find** dialog. This is where the active flag is used. Un-checking a search field in the find dialog corresponds to setting `active=0`.

## See also

* [searchcriteria table][3]
* [searchcriteriagroup table][4]
* [searchcriterion table][5]
* [searchcriterionvalue table][6]
* [selection table][7]

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

[2]: ../../../saint/learn/index

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

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

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

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

[7]: ../../../database/tables/selection

[img1]: /media/loc/en/api/search/dynsel-card.png


## Related topics

- [Selection](/en/search-options/selection/learn/index.md)
- [selection](/en/api/mdo-providers/reference/selection.md)
- [SelectionDynamicSelectionV2](/en/api/archive-providers/reference/selectiondynamicselectionv2.md)
- [ContactDynamicSelection](/en/api/archive-providers/reference/contactdynamicselection.md)
- [AppointmentDynamicSelection](/en/api/archive-providers/reference/appointmentdynamicselection.md)
- [ProjectDynamicSelection](/en/api/archive-providers/reference/projectdynamicselection.md)
