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

# Using vendor and business unit databases

> Connect vendor and business unit databases to data sets in ABBYY FlexiCapture, map columns, set normalization, and manage data set records.

When processing an invoice, ABBYY FlexiCapture first looks for the vendor (the company that issued the invoice) and the business unit (the company or department that received the invoice).

In most cases, the vendor determines the language of the invoice and the formatting of its numbers, dates, and amounts. The business unit determines the tax rates and applicable regulatory requirements. ABBYY FlexiCapture uses all of this information when capturing invoice data and applying validation rules.

To help the program locate the vendor and business unit fields, you can use vendor and business unit databases. These must be connected to the data sets in your Document Definition.

A data set is a local copy of a table from an external database that stores information about vendors or business units. Its values can be typified and normalized, and it can be periodically updated to stay synchronized with its external database. For more information, see [Preparing vendor and business unit databases](/flexi-capture/invoice-reader/ir-preparing-db).

Vendor and business unit databases can also be used for automatic and manual data checks.

You do not have to use vendor and business unit databases, but note the following:

* If vendor and business unit databases are used, ABBYY FlexiCapture can more reliably detect companies by looking for additional company information on invoice images. It can also confirm that a detected vendor is a "known" vendor. Additionally, if a vendor database is used, you can [train fields](/flexi-capture/invoice-reader/ir-operator-training).
* If no vendor or business unit databases are used, ABBYY FlexiCapture uses neural networks to look for vendor and business unit names and addresses on invoice images. For more information, see [Detecting the main fields](/flexi-capture/invoice-reader/ir-search-fields#neuralnetwork). You also cannot [train fields](/flexi-capture/invoice-reader/ir-operator-training), because ABBYY FlexiCapture cannot reliably identify vendors without a vendor database.
* If you have no vendor databases but still want to use field training, you can accumulate company information by adding records to your data sets while capturing invoices. For more information, see [Looking up vendors and business units in the database](/flexi-capture/invoice-reader/ir-data-set-using#addnew).

## Connect a vendor or business unit database

Vendor and business unit databases are connected in the same way:

<Steps>
  <Step title="Open the Document Definitions dialog box">
    Open the **Project** menu and click **Document Definitions...**.
  </Step>

  <Step title="Edit the Document Definition">
    Click the **Edit...** button in the dialog box that opens.
  </Step>

  <Step title="Open the Document Definition properties">
    Open the **Document Definition** menu and click **Document Definition Properties...**.
  </Step>

  <Step title="Open the Data Sets tab">
    Open the **Data Sets** tab in the dialog box that opens.
  </Step>

  <Step title="Open the data set">
    Double-click the **BusinessUnits** (or **Vendors**) row, or click the **Set Up...** button. The **Data Set** dialog box opens.

    A data set is essentially a table of data with a fixed set of columns and types that you cannot change. You match each data set column with a column from an external database. If a database does not contain a table with the necessary data, create a view with this data and specify the view as the table.
  </Step>

  <Step title="Select the source">
    Select **Database** from the **Source** drop-down list.

    <Note>
      Select the **Script** source type only if you plan to use a script to update the data set. For more information, see [Updating data sets](/flexi-capture/invoice-reader/ir-data-set-update).
    </Note>
  </Step>

  <Step title="Specify the connection string">
    Specify the database connection string. You can select one of the existing environment variables from the project or define a new string by clicking the **Specify...** button. Using an environment variable from the project lets you move the project and connect to databases with the same structure without editing the Document Definition.
  </Step>

  <Step title="Select the schema and table">
    Select the **Data schema** and **Database table**.
  </Step>

  <Step title="Match the columns">
    Match the columns from the data set with their corresponding columns in the external database. For each data set column, you can specify the corresponding external database column or a value.

    The **Match fields** list contains:

    * The names of columns in the data set.
    * The corresponding columns from the external database.
    * The **Found** column, which contains a checkmark when a match between the data set field and a database column has been established.
    * The **Normalization** column, which shows the type of normalization used for the value.

    By default, each field in the **External Database** column of the data set contains the value, which means that no external database column has been specified. Normalization makes it possible to treat several slightly different values as identical. For more information, see [Normalization of values in data sets](/flexi-capture/invoice-reader/ir-normalization).

    To map each column, select it in the table and click the **Edit...** button. For more information, see [Map a data set column to a database column](#map-a-data-set-column-to-a-database-column).
  </Step>

  <Step title="Add custom columns (optional)">
    Use the **Add...** button to add custom columns to a data set and specify corresponding columns in an external database.

    <Note>
      Use the **Edit...** and **Delete** buttons to manage complex columns. Predefined columns (indicated by the lock icon) cannot be deleted.
    </Note>
  </Step>

  <Step title="Set an update period">
    Specify a database update period in the data set if automatic updates are required.
  </Step>

  <Step title="Enable script validation (optional)">
    To validate records using a script, enable the **Check records using scripts** option. For more information, see [Data set validation scripts](/flexi-capture/appendix/scripts/script-validation).
  </Step>

  <Step title="Save your changes">
    Save your changes.
  </Step>
</Steps>

### Map a data set column to a database column

For each column, select it in the **Match fields** list, click the **Edit...** button, and configure the mapping in the **Data Set Column Mapping** dialog box:

<Steps>
  <Step title="Select the database column">
    Select the matching database column from the **Database columns** list.

    Invoices from the same vendor can contain different company names and addresses. When several values correspond to the same vendor (the same VATID), place them in different columns of the external database table or view, such as **Name1**, **Name2**, **Address1**, ..., **AddressN**. You can then select **Several columns...** from the list and specify any number of database columns as matches for the data set column.

    <Note>
      The external database may contain only one value for the company name or street, but these fields can have several common variants on invoices. To achieve the best detection quality, the text in these fields on an invoice should be as close as possible to the corresponding text in the data set. For more information, see [Multiple-value columns in a data set](/flexi-capture/invoice-reader/ir-preparing-db#complexcolumns).
    </Note>

    To create more than one column, specify the number of permitted columns for a field in the **Max variant count** box. Operators can add values to these columns later.

    <Note>
      If you specify a number that is less than the actual number of columns, it is increased automatically when the data set is updated. If you specify a number greater than the actual number of columns, empty columns are added.
    </Note>

    If your database has no matching column for a data set column, refer to the [Vendors data set](/flexi-capture/invoice-reader/ir-columns-vendors) and [BusinessUnits data set](/flexi-capture/invoice-reader/ir-columns-bu) sections.
  </Step>

  <Step title="Select the normalization type">
    Select an entry from the **Normalization** list that best fits the type of data in the column. For more information, see [Normalization of values in data sets](/flexi-capture/invoice-reader/ir-normalization). If necessary, enable the **Store normalized value** option.
  </Step>

  <Step title="Set the Cannot be empty option">
    Enable the **Cannot be empty** option if necessary.

    <Note>
      When enabled, the **Cannot be empty** option tells the program that a column has to contain values. If it turns out to contain no values, the record is marked as invalid.
    </Note>

    <Info>
      If your Document Definition contains a **Vendors** data set that uses an external database as its source, and the value of the **Vendor** field depends on the value of the **Business Unit** field, **Cannot be empty** is enabled for the **BusinessUnitId** column by default. If the **Vendors** data set uses another source, enable this option manually.
    </Info>
  </Step>

  <Step title="Save the mapping">
    Save the changes in the **Data Set Column Mapping** dialog box.
  </Step>
</Steps>

## The Data Sets tab

All data sets are listed on the **Data Sets** tab. This list includes some additional information:

* The name of the data set in the **Name** column.
* The type of the selected source in the **Source** column.
* The total number of records in the **Record count** column.
* The status of the data set (whether it is enabled) in the **Connected** column.

<Note>
  The total number of records is displayed only if the **Cache data** option is enabled in the data set's properties.
</Note>

You can manage the data sets using the buttons to the right of the list:

* **Set Up...** opens the properties dialog box of the selected data set.
* **Update** updates the selected data set.
* **Check...** checks the data set (data is displayed in a separate window).
* **Add...** creates a new data set.
* **Rename...** renames the selected data set.
* **Delete** deletes the selected data set.
* **View\...** opens a dialog box that lets you view and edit data from the selected data set.
* **Clean Up** deletes all records in the data set.

The **Vendors** and **BusinessUnits** data sets are stored within the project and must be synchronized with an external database, whose data may change over time. Synchronization occurs when the project is opened, but only if the time elapsed since the previous synchronization exceeds the specified update period. For more information, see [Updating data sets](/flexi-capture/invoice-reader/ir-data-set-update).

## <a id="viewing" />View and edit data set records

To view or edit a data set, select it on the **Data Sets** tab of the Document Definition properties dialog box and click the **View\...** button.

All records belong to one of three record groups. You can select the record group you want to view from the **Record group** drop-down list.

* **General** contains only valid records.
* **Deleted** contains records that were deleted by a user. These records are not used during recognition and are not displayed as results for a [database search](/flexi-capture/invoice-reader/ir-data-set-using). If the data set is updated, these records are not restored.
* **Invalid** contains invalid records.

Click the **Set...** button to sort and filter records by their values in one of the list's columns. The **Reset** button disables the filter.

Different operations are available for each of the record groups:

| Operation   | General                                            | Deleted                                        | Invalid                                            |
| ----------- | -------------------------------------------------- | ---------------------------------------------- | -------------------------------------------------- |
| **Edit** \* | Edits a record. Edited records remain in the list. | —                                              | Edits a record. Edited records remain in the list. |
| **Add** \*  | Adds a record to the list.                         | —                                              | —                                                  |
| **Delete**  | Moves the record to **Deleted**.                   | —                                              | Moves a record to **Deleted**.                     |
| **Restore** | —                                                  | Restores the record (moves it to **General**). | Validates the record (moves it to **General**).    |

\* Adding and editing records is only possible if the **Primary key** option is enabled. Records in the **PurchaseOrders** and **PurchaseOrderItems** default data sets cannot be added or edited.

<Note>
  When adding or editing records, the number of values you can specify for a field cannot exceed the **Max variant count** set for that field in the **Data Set Column Mapping** dialog box. You can use the <img src="https://mintcdn.com/abbyy/39LtOHLEp1q7pm1x/images/flexi-capture/Add_to_DB.png?fit=max&auto=format&n=39LtOHLEp1q7pm1x&q=85&s=716437d729d5ff1658d99b6123c1c8aa" alt="" style={{display:"inline-block",verticalAlign:"middle",margin:0}} width="26" height="22" data-path="images/flexi-capture/Add_to_DB.png" /> and <img src="https://mintcdn.com/abbyy/mpS3pcxC_lkohQUS/images/flexi-capture/Remove_from_DB.png?fit=max&auto=format&n=mpS3pcxC_lkohQUS&q=85&s=af76788e1141f33096557389df7b704c" alt="" style={{display:"inline-block",verticalAlign:"middle",margin:0}} width="26" height="22" data-path="images/flexi-capture/Remove_from_DB.png" /> buttons in the **Add Record** and **Edit Record** dialog boxes to manage records.
</Note>

<Note>
  To apply sorting and filtering to newly added or edited records, set the filter again.
</Note>

### Database Check rules

The Invoice Document Definition contains rules that are used to check data in the **Vendor** and **Business Unit** groups of fields against the database. These are standard rules of the Database Check type, named **(Rejected) Vendor should be found in the database** and **(Rejected) Business Unit should be found in the database**. To learn how to find rules in the list, see [Rules](/flexi-capture/invoice-reader/ir-setting-rules).

You can view the properties of these rules to find out how each field in the **Vendor** and **Business Unit** groups is checked:

* Which fields must exactly match records in the data set (and, by extension, in the database).
* Which fields do not have to match perfectly.
* Which fields are simply copied from the database.

You can also specify a field to be used as a primary key for selecting a record from the data set.

For more information, see [Database Check rule](/flexi-capture/templates/rule-bd).

Database Check rules are applied automatically when the invoice is recognized, and then each time an Operator changes fields in the group during verification.

### Look up records while processing invoices

If a vendor or a business unit has not been determined automatically, the Operator can select the appropriate record from the database (the data set).

For more information, see [Looking up vendors and business units in the database](/flexi-capture/invoice-reader/ir-data-set-using).

### Modify and add vendor and business unit records

You can allow Operators to add new vendor and business unit records (if they are not found in the database) to data sets during verification and edit existing entries. This data is not stored in external vendor and business unit databases, but it is used during invoice processing and rule checks. For more information, see [Enabling additional program features for operators](/flexi-capture/invoice-reader/ir-advanced-options-activation).

For more information about database lookups, see [Looking up vendors and business units in the database](/flexi-capture/invoice-reader/ir-data-set-using).
