--- title: "Set up validation rule of type Query" slug: "set-up-validation-rule-of-type-query" description: "Learn to set up query validation rules to ensure data integrity by validating field values against dynamic queries in your data management processes." tags: ["Task topic"] updated: 2026-03-20T08:30:02Z published: 2026-03-20T17:44:40Z canonical: "docs.staedean.com/set-up-validation-rule-of-type-query" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.staedean.com/llms.txt > Use this file to discover all available pages before exploring further. # Set up validation rule of type Query Use validation rules to check if the data is in line with the defined standards. To validate data, you can use several validation types. This topic explains how to set up a validation rule of type '**Query**'. Use a query validation rule to validate if an entered field value is allowed using a dynamic query. Using a dynamic query, you can validate the field value based on one or more field values in another table. Examples of validations where you can apply a query validation rule: - On creating a sales order, check if address information or contact information is defined for the selected customer. If no address or contact information is defined, the customer cannot be used on a sales order. - On the worker setup, for the worker position, a cost center can be defined in the 'Cost center' financial dimension. Validate if the defined cost center is active. If not active, a warning or error message is given for the worker. - On terminating an employee, check if positions are reporting to the employee. If positions are still reporting to the employee, you cannot terminate the employee. Before you can set up a query validation rule, set up the dynamic query to be used. You can add validation rules in these ways: - Manually. - Select the fields to be validated from a page. ### Steps 1. Click **Data quality management**. 2. On the **Data quality policies** tab, in the list, click the link of the desired data quality policy. > [!NOTE] > **Note** > > If you want to edit another data quality policy version than the currently shown version, first select the desired version. To do so, on the **Action Pane**, on the **Version** tab, click **Versions**. On the dialog, select the desired version and click **OK**. 3. Sub-task: Manually create validation rule. 1. You can manually create a validation rule and define the table and field which value must be validated. On the **Validation rules** tab, click **Add**. 2. Define the table of the field which value must be validated. In the **Table** field, enter or select a value. > [!NOTE] > **Note** > > If you want to validate field values in inherited tables, define the child table instead of the base table. For example, instead of DirPartyTable, use DirOrganization or DirPerson. 3. Define the field which value must be validated. In the **Field** field, enter or select a value. 4. Sub-task: Create validation rules by selecting fields. 1. You can create validation rules by selecting the fields, which value must be validated, from a page. On the **Validation rules** tab, click **Select** fields. 2. Open the page from which you want to select fields. 3. On the Field picker dialog, click Select fields. 4. Click the '**+**' button for each field that you want to select. 5. On the **Field picker** dialog, click **Done**. 6. On the **Field picker** dialog, click **Submit** to save the selected fields to the validation rule. 5. Define to which records the validation rule is applied. You can apply a validation rule to: In the **Record type** field, select an option. - New records only. - Existing records only. - New records and existing records. 6. In the **Validation type** field, select '**Query**'. 7. In the **Event** field, select '**Record validation**'. > [!NOTE] > **Note** > > - A query validation rule applies only to record validation. > - The validation rule is applied just before the standard record validation is done. 8. Define what is done if the validation rule is not met: In the **Outcome** field, select an option. > [!NOTE] > **Note** > > For each validation rule, you can define a message to be shown. If you do not define a validation rule message, in case of a warning or error, a default message is shown. - **Warning**: A warning message is shown. The record or the field value is saved. - **Error**: An error message is shown. The record or the field value is not saved. 9. In the **Dynamic query** field, enter or select a value. 10. Usually, you use the current record as the range for the dynamic query. Select **Yes** in the **Set current record in query** field. > [!NOTE] > **Note** > > If you do not use the current record as range, set the ranges manually. 11. Sub-task: Set the result fields. 1. Specify which dynamic query fields are the result fields. Use a result field to verify that the validated field contains a valid value. On the **Properties** tab, click **Add**. 2. Select the **Result check box**. 3. Select the result field from the dynamic query. In the **Field** field, enter or select a value. > [!NOTE] > **Note** > > You can use fields from a table other than the validated field's table. 4. Use a range expression to define the values that must be met during validation. For example, if the result field must have a value, the range expression is: != "" To define a range expression, you can use: In the **Range expression** field, type a value. > [!NOTE] > **Note** > > For more information on how to define ranges in the Range expression field, refer to [Advanced filtering and query syntax](https://learn.microsoft.com/en-us/dynamics365/fin-ops-core/fin-ops/get-started/advanced-filtering-query-options). - A fixed value or a range of values using the advanced query syntax - A static method that defines the range. For example, you can use the `SysQueryRangeUtil` class to apply advanced date queries. 12. Sub-task: Set query ranges and range values. 1. You can use other ranges in the dynamic query than the current record. On the **Properties** tab, click **Add**. > [!NOTE] > **Note** > > Only set ranges if the **Set current record in query** field is set to '**No**'. 2. Define the ranges to be applied to the dynamic query. In the **Field** field, enter or select a value. > [!NOTE] > **Note** > > To define a range, you can only use dynamic query fields that are set as range in the dynamic query setup. 3. To set a range, you can use these types of values: In the **Value type** field, select an option. - **Field**: Define a field which value is used as range in the dynamic query. The field value is taken from the validated record. - **Fixed value**: Define a fixed value that is used as range in the dynamic query. - **Custom**: Use a custom class and custom method to define a range. - **Custom**: Use a range expression to define a range. 4. In the **Condition type** field, select an option. 5. If the **Value type** is **Field**, define the field which value is used as range in the dynamic query. In the **Field name** field, enter or select a value. > [!NOTE] > **Note** > > Usually, you define the same field as the field that is used for the range. 6. If the **Value type is Fixed** value, define the value that is used as range in the dynamic query. In the **Fixed value field**, enter or select a value. 7. If the **Value type** is **Custom**, define the custom class with the method that you use to define a range. In the **Class name field**, enter or select a value. > [!NOTE] > **Note** > > The custom class must extend the **DQSCustomValidationBase** class. 8. If the **Value type** is **Custom**, define the method that you use to define a range. The method must exist in the defined custom class. In the **Method name** field, enter or select a value. 9. If the value type is '**Range expression**', define the range expression that is used to define the range for the dynamic query. To define a range expression, you can use: In the **Range expression** field, type a value. > **Note** > > For more information on how to define ranges in the **Range expression** field, refer to [Advanced filtering and query syntax](https://learn.microsoft.com/en-us/dynamics365/fin-ops-core/fin-ops/get-started/advanced-filtering-query-options). - A fixed value or a range of values using the advanced query syntax - A static method that defines the range. For example, you can use the `SysQueryRangeUtil` class to apply advanced date queries. 13. Close the page. ## Related - [Set up validation rule of type Query](/set-up-validation-rule-of-type-query-flow.md)