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

# Rules

> Create, filter, and disable validation rules in ABBYY FlexiCapture for Invoices, including status-changing prefixes and country-specific rule conditions.

FlexiCapture for Invoices uses rules to validate invoices automatically. Upon validation, an invoice is assigned a status and a list of issued errors and warnings is generated, enabling the Operator to decide whether the invoice needs to be verified manually. While verifying an invoice in the document editor, the Operator sees the list of errors detected by the rules and can use this list to navigate and review the defective fields.

ABBYY FlexiCapture for Invoices already includes predefined validation rules for invoices commonly used in different countries. For more information, see [Available rules](/flexi-capture/invoice-reader/ir-rules). Users can modify or remove existing rules and create new custom rules.

## Features specific to rules in FlexiCapture for Invoices

For detailed instructions on working with rules in FlexiCapture, see [Rule validation](/flexi-capture/templates/rules).

Rules in FlexiCapture for Invoices have the following specific features:

### Rules may affect the status of a document

To make a rule affect the status of a document, the rule must have a corresponding prefix in its name. Rules with names prefixed with **(Exception)** or **(Rejected)** change the status of an invoice to **Exception** or **Rejected** if the rule detects errors in that invoice.

### Rules may be applied to a certain set of countries

To implement this feature, use conditions for applying rules. For more information, see [Rule validation](/flexi-capture/templates/rules).

Rules detect the country of an invoice based on the country of the business unit to which the invoice has been issued.

If a certain kind of validation is relevant only to particular countries, only the relevant countries should be specified in the rule conditions. Conversely, if invoices from all countries must be validated except one particular country, be sure to exclude that country in the rule conditions (the condition must apply the rule only if the country of the business unit is not the same as the name of the excepted country).

## Use the list of rules

### View the complete list of rules

To view all the rules set up for the project:

<Steps>
  <Step title="Open the Document Definition properties">
    From the **Document Definition** menu, select **Document Definition Properties...**.
  </Step>

  <Step title="Open the Rules tab">
    In the dialog box that opens, click the **Rules** tab.
  </Step>

  <Step title="Show all rules">
    In the **Show rules** list, select **owned by Document Definition and its children**.
  </Step>
</Steps>

To view all the rules that are applied to invoices from a particular country (for example, Germany), use the filter.

### Set up a filter

<Steps>
  <Step title="Open the filter">
    In the **Document Definition Properties** dialog box, click the **Rules** tab and then click the **Filter...** button.
  </Step>

  <Step title="Select the country field">
    In the **Filter** dialog box, select **If this condition is true** and then select the **Invoice Layout\BU\Country** field, which defines the country of the business unit.
  </Step>

  <Step title="Set the condition">
    Select the **Overlaps with set** condition from the drop-down list.
  </Step>

  <Step title="Choose the countries">
    Use the **Select...** button to specify the required countries in the field below. A **Field Value** dialog box opens, where you select the countries for which to display the rules. For Germany, for example, select **DE**.
  </Step>

  <Step title="Apply the filter">
    Click **OK**.
  </Step>
</Steps>

The list now displays all the rules that are applied to invoices of the country you specified in the filter.

<Note>
  The condition that triggers a rule is shown in the **Apply rule** column.
</Note>

### Find a rule in the list

You can use the following filtering criteria to find a rule:

* Rule name
* The name of a field referred to by the rule
* The condition that triggers the rule

<Steps>
  <Step title="Open the filter">
    In the **Document Definition Properties** dialog box, click the **Rules** tab and then click the **Filter...** button.
  </Step>

  <Step title="Specify the criteria">
    In the **Filter** dialog box, you can select the name of the rule you want to find (the names are listed alphabetically), select a field referred to by the rule, or specify the condition that triggers the rule.
  </Step>
</Steps>

For detailed instructions on using the filter, see [Rule validation](/flexi-capture/templates/rules).

## Create new rules

To create a new rule:

<Steps>
  <Step title="Open the Document Definition properties">
    From the **Document Definition** menu, select **Document Definition Properties...**.
  </Step>

  <Step title="Open the Rules tab">
    In the dialog box that opens, click the **Rules** tab.
  </Step>

  <Step title="Show all rules">
    In the **Show rules** list, select **owned by Document Definition and its children**.
  </Step>

  <Step title="Select the field">
    Select the field where the rule is stored. This may affect the operation of some rules (for example, how its error messages are generated). If you have doubts as to which field to choose, select the topmost node, that is, **Invoice Layout**.
  </Step>

  <Step title="Add a new rule">
    Click **New Rule...**.
  </Step>

  <Step title="Choose the rule type">
    In the dialog box that opens, select one of the standard rule types, or select **Script**, which allows you to write your own rule.
  </Step>
</Steps>

<Note>
  For detailed information about each rule type and for instructions on how to create them, see [Rule validation](/flexi-capture/templates/rules).
</Note>

The following steps are specific to creating rules in FlexiCapture for Invoices:

<Steps>
  <Step title="Specify the rule properties">
    After you select a rule type, specify:

    * **Name** — The name should reflect the kind of validation the rule performs. Errors issued by the rule are displayed to the Operator in the format **Rule name: Error message.** To make the rule affect the status of invoices, prefix its name with **(Exception)** or **(Rejected)**, depending on the status you want assigned to an invoice if the rule detects an error.
    * **Severity** — Severity flags help the Operator review the errors and warnings and decide which invoices to verify manually. Data export can also depend on the severity flag. For example, you can:

      * Export documents that have no rule errors but have rule warnings to your working database.
      * Export documents that have rule errors to an exceptions folder.
      * Prohibit the export of documents with errors altogether.

      For more information about setting up export based on the severity of a rule, see [Rule validation](/flexi-capture/templates/rules).
    * **Rule is enabled** — Whether the rule is enabled after it is created.
  </Step>

  <Step title="Specify the condition for applying the rule">
    Typically, this condition is defined by the value of the **Invoice Layout\BU\Country** field. By default, the rule is always applied (**Apply rule = always**). To apply the rule only under certain conditions:

    1. From the **Apply rule** list, select **on condition**.
    2. Click **Edit...** to modify the condition.
    3. Select the field whose value triggers the rule (**Invoice Layout\BU\Country**).
    4. Specify the condition and, if applicable, allowed and prohibited values.

    **Example 1.** The rule must be applied to German invoices. Select the **Belongs to set** condition, click **Add**, and add the value **DE**.

    **Example 2.** The rule must be applied to all invoices except German and French invoices. Select the **Does not belong to set** condition, click **Add**, and add the values **DE** and **FR**.
  </Step>

  <Step title="Set up the rule">
    For detailed information, see [Rule validation](/flexi-capture/templates/rules).
  </Step>
</Steps>

## Disable or delete a rule

To disable a previously set up rule:

<Steps>
  <Step title="Find the rule">
    Find the rule in the list. For more information, see [Find a rule in the list](#find-a-rule-in-the-list).
  </Step>

  <Step title="Clear the Enabled option">
    Clear the box in the **Enabled** column next to the rule. Alternatively, double-click the rule to open its **Properties** dialog box and clear the **Enabled rule** option on the **General** tab.
  </Step>
</Steps>

If you are certain that you no longer need a rule, you can delete it. To delete a rule:

<Steps>
  <Step title="Find the rule">
    Find the rule in the list. For more information, see [Find a rule in the list](#find-a-rule-in-the-list).
  </Step>

  <Step title="Delete it">
    Select the rule by clicking its name in the list and click **Delete**.
  </Step>
</Steps>
