Skip to main content
As the word implies, a dynamic selection is a selection that is bound to change dynamically and it’s based on search criteria and not just static members. A typical criterion would be “Add all contacts with a specific business type”. This would cause the member count of this selection to increase each time a new contact is added to the database that matches the business type specified as a search criterion for this selection. You may have as many search criteria as you want.

Add restrictions to the selection

CS

Initialize and declare the variables

The first few lines of the codes initialize and declare the variables that we plan to use in the code.
If you are new to selections, check out how to use criteria in selection searches.
  • storageType - we use the Criteria type since this is a selection
  • providerName - we use ContactDynamicSelection since we plan to create a dynamic selection
  • storageKey - we use selection=61 since this will allow us to create a restriction for that particular selection ID. In the statement, selection is the name of the table and 61 is the primary key ID (selection_id).
  • staticColumns - we use name and contactId
  • handledColumns - retrieved based on storageType and providerName
CS

GetSpecifiedCriteriaInformationWithDefaults

CS
With the execution of the above code, we have retrieved criteria information from a set of saved criteria, for specific set columns. In the case of the example, this would be empty.

Create variable to store restrictions

The next step is to create a variable that could be used to store the restrictions.
CS
The Dictionary class from the System.Collection.Generic namespace is used to store the restriction as a key-value pair. The key is the name of the field the restriction is on, and the value is the ArchiveRestrictionInfo object that describes the restriction itself. Once this is done we may add the necessary restrictions as shown below.
CS

Save

Once all the required restrictions have been added the created restriction can be saved by executing the following statement.
CS
Though we have added only 2 restrictions explicitly, it can be seen that there are many conditions. This is because we have got the criteria with the GetSpecifiedCriteriaInformationWithDefaults method, which returns all criteria with default values. However, this would not be affecting the outcome of the selection since the other criteria are not active - they have no values to search for.

View the result with SelectionAgent or ArchiveAgent

We may also be able to view the results of the restriction with the SelectionAgent or the ArchiveAgent. The following code shows how we can use the SelectionAgent to retrieve information about the particular selection.
If we wish to retrieve the details of the members in the selection we need to use the ArchiveAgent. After authenticating, set the parameters like below.
CS
Then call GetArchiveListByColumns() and follow the patten for getting selection members. Output: