Document Matching Criteria
Matching criteria determine how incoming documents are associated with Business Central records. This page explains how to configure effective matching rules.
Matching Overview
Purpose
Matching criteria:
- Identify which BC record a document belongs to
- Enable automatic routing
- Extract key information from documents
How Matching Works
- Document arrives in source folder
- Criteria are iterated in primary-key order (Table No., Source ID, then Criteria ID alphabetically)
- First matching criterion determines the record
- Document routed to that record's folder
There is no separate Priority field on the Incoming Match Criteria table. To control evaluation order, use Criteria ID values that sort the way you want -- for example, 10-EXACT, 20-PATTERN, 99-CATCHALL.
Criteria Types
Available Criteria Types
| Type | Description | Use Case |
|---|---|---|
| Email Match | Extract email addresses from content | Email-originated documents |
| Pattern Match (Regex) | Regex on document content | Invoices with patterns |
| FileName Pattern Match (Regex) | Regex on filename | Structured filenames |
| FileName with primary key | Extract PK from filename | ID in filename |
| Create Document | Regex on document content | Content-based matching |
Configuring Criteria
Accessing Criteria Setup
The criteria list cannot be found with Tell Me search:
- Open it via the Incoming Criterias action -- on the Incoming Sources list, or on the SharePoint Table Mapping card or list
- Configure criteria for each source
Criteria Fields
| Field | Type | Description |
|---|---|---|
| Table No. | Integer | The BC table number |
| Source ID | Code | Which incoming source |
| Criteria ID | Code | Unique criteria identifier |
| Type | Enum (Criteria Type EFQ) | Matching method |
| Match Field No. | Integer | BC field to match |
| Match Parameter | Text | Pattern or search term |
| Optional Subfolder | Text | Route to subfolder |
| Use OCR Service | Boolean | Apply OCR before matching |
| Store Metadata | Boolean | Reserved -- currently has no effect (see OCR Integration below) |
Email Match
Description
Extracts email addresses from the document content using a built-in regex pattern and matches them against the specified BC field. The Match Parameter field is not used for this criteria type; email extraction uses a hardcoded email address pattern.
Configuration
| Field | Value |
|---|---|
| Type | Email Match |
| Match Field No. | Field to match (e.g., E-Mail field) |
Use Case
Emails forwarded to a shared mailbox synced to SharePoint. The email address found in the document is matched against a BC field.
Pattern Match (Regex)
Description
Uses regular expressions to find patterns in document content.
Warning: The document content is converted to lowercase before the regex runs. Write patterns entirely in lowercase -- a pattern containing uppercase literals (such as
INV-\d{6}) will never match content. Filename criteria are unaffected; they match the raw filename as-is.
Capture groups are not used for extraction. The entire regex match becomes the value that is filtered against the match field (as a case-insensitive @ filter), so design the pattern so the whole match equals the field value.
Configuration
| Field | Value |
|---|---|
| Type | Pattern Match (Regex) |
| Match Field No. | Field to match result against |
| Match Parameter | Regex pattern (lowercase) |
| Use OCR Service | Yes (for scanned docs) |
Regex Examples
| Pattern | Finds |
|---|---|
inv-\d{6} |
INV-123456 (content is lower-cased first, so this matches) |
po\s*#?\s*\d+ |
PO # 12345 |
from:\s*.+ |
From: sender line |
Remember that the whole match is used as the filter value: po\s*#?\s*\d+ yields po# 12345 -- including the "po#" prefix -- which only matches a field that literally contains that text. To match a field holding just the number, write the pattern to match just the number, for example [a-z]\d{5,} or \d{5,}.
Best Practices
- Test patterns thoroughly
- Escape special characters
- Write patterns in lowercase only
- Make the whole match equal the field value -- capture groups are ignored
FileName Pattern Match (Regex)
Description
Matches patterns in the filename (not content). The raw filename is matched as-is -- it is not lower-cased, so patterns may contain uppercase literals. As with content matching, capture groups are not used: the entire match becomes the value filtered against the match field.
Configuration
| Field | Value |
|---|---|
| Type | FileName Pattern Match (Regex) |
| Match Field No. | Field to match |
| Match Parameter | Regex for filename |
Examples
| Pattern | Matches Filename | Match value used |
|---|---|---|
^C\d+ |
C12345_invoice.pdf | C12345 |
\d{8} |
20240115_doc.pdf | 20240115 |
Design the pattern so the whole match equals the field value -- for example ^C\d+ rather than ^C(\d+)_, whose whole match would include the trailing underscore and never match a customer number.
FileName with primary key
Description
Splits the filename by the separator specified in Match Parameter and uses the resulting parts to look up a record by its primary key. The second part is used as the table number, and subsequent parts are matched against the primary key fields.
Configuration
| Field | Value |
|---|---|
| Type | FileName with primary key |
| Match Parameter | Separator character used to split the filename (e.g., _) |
Requirements and Pitfalls
- The target table (taken from the second split part) must already have a SharePoint Table Mapping; if no mapping exists, the criterion silently fails to match.
- The split is applied to the full filename including the extension, so the last part keeps the extension.
Invoice_18_V00123.pdfsplits intoInvoice,18, andV00123.pdf-- and the lookup then searches for a vendor whose No. is literallyV00123.pdf, which fails. - For the lookup to succeed, the last split part must exactly equal the key value. In practice that means the filename must be built without an extension (e.g.
Invoice_18_V00123) or the extension must be part of the stored key value. - The imported document is renamed to the first split part (
Invoicein the example), which carries no file extension -- the file lands in SharePoint without an extension.
Example
Filename: Invoice_18_V00123 (no extension) with Match Parameter _ Splits into: Invoice, 18 (table no.), V00123 (primary key value -- matches Vendor V00123) The first part (Invoice) becomes the new filename for the imported document (with no extension).
Create Document
Description
Uses regular expressions to match document content against BC records, similar to Pattern Match (Regex). Despite its name, this criteria type does not create new records; it matches existing ones using regex on the document content (or OCR text if enabled). The same rules apply as for Pattern Match (Regex): the content is lower-cased before matching, so write the pattern in lowercase, and the entire match (not capture groups) is used as the filter value.
Configuration
| Field | Value |
|---|---|
| Type | Create Document |
| Match Field No. | Field to match result against |
| Match Parameter | Regex pattern |
| Use OCR Service | Yes (for scanned docs) |
Use Case
Regex-based content matching with the same approach as Pattern Match.
Evaluation Order
How the Connector Orders Criteria
Criteria are stored with the primary key TableNo, SourceID, CriteriaID. For a given Source, the connector iterates criteria in primary-key order (Criteria ID alphabetically). First match wins and remaining criteria are skipped.
There is no separate Priority field. To make evaluation order obvious and controllable, use Criteria ID values that sort in the desired order.
Naming Strategy
| Criteria ID | Criteria Type |
|---|---|
10-EXACT |
Most specific (exact match) |
20-PATTERN |
Pattern match |
30-GENERAL |
General patterns |
99-CATCHALL |
Catch-all |
Subfolder Routing
Optional Subfolder
Route matched documents to specific subfolders:
| Criteria | Subfolder | Result |
|---|---|---|
| Invoice pattern | Invoices | Goes to /Record/Invoices/ |
| Contract pattern | Contracts | Goes to /Record/Contracts/ |
Configuration
| Field | Value |
|---|---|
| Optional Subfolder | Invoices |
OCR Integration
When to Use OCR
Enable OCR for:
- Scanned documents
- Image-based PDFs
- Documents without searchable text
Supported File Types
OCR only runs for files with these extensions: .pdf, .jpeg, .jpg, .png, .tif, .tiff, .bmp. For any other file type the connector silently falls back to matching against the raw file bytes -- no warning is given.
OCR Configuration
OCR uses the Azure Computer Vision API (v3.2 read/analyze endpoint). The OCR service is configured in SharePoint Setup with the following settings:
| Setting | Location | Description |
|---|---|---|
| OCR Service URL | SharePoint Setup | Azure Computer Vision endpoint |
| OCR Subscription Key | SharePoint Setup | Azure subscription key |
On each criteria record:
| Field | Value |
|---|---|
| Use OCR Service | Yes |
| Store Metadata | Reserved -- currently has no effect |
OCR Process
- Document sent to Azure Computer Vision API (v3.2 read/analyze endpoint)
- Text extracted
- Pattern matching on extracted text
- On import, the OCR result JSON is uploaded alongside the document (as
<name>.metadata.json) whenever OCR ran -- regardless of the Store Metadata setting, which currently has no effect
Example Configurations
Vendor Invoice Matching
Match the vendor number printed somewhere on the invoice (content patterns must be lowercase; the field filter is case-insensitive, so v00123 still matches vendor V00123):
| Field | Value |
|---|---|
| Type | Pattern Match (Regex) |
| Match Field No. | 1 (No.) |
| Match Parameter | v\d{5} |
| Optional Subfolder | Invoices |
| Use OCR Service | Yes |
Customer Number in Filename
The whole match (C12345 in C12345_invoice.pdf) is filtered against the customer number:
| Field | Value |
|---|---|
| Type | FileName Pattern Match (Regex) |
| Match Field No. | 1 (Customer No.) |
| Match Parameter | ^C\d+ |
PO Number Matching
Match a run of five or more digits (for example the number in "PO # 12345") -- the whole match, just the digits, is filtered against Your Reference:
| Field | Value |
|---|---|
| Type | Pattern Match (Regex) |
| Match Field No. | 3 (Your Reference) |
| Match Parameter | \d{5,} |
| Use OCR Service | Yes |
Testing Criteria
Before Production
- Create test criteria
- Add test documents to source
- Run matching
- Verify results
- Adjust patterns as needed
Common Issues
| Issue | Check |
|---|---|
| No match | Pattern doesn't match content |
| No match (content criteria) | Pattern contains uppercase literals -- content is lower-cased before matching |
| No match (FileName with primary key) | Target table has no SharePoint Table Mapping, or the last filename part includes the extension |
| Wrong match | Criteria ID sort order, pattern too broad |
| OCR needed | Enable OCR service |
Troubleshooting
Pattern Not Matching
| Check | Resolution |
|---|---|
| Regex syntax | Validate pattern |
| Content present | Check document has text |
| OCR needed | Enable for scanned docs |
Wrong Record Matched
| Check | Resolution |
|---|---|
| Criteria ID sort order | Rename Criteria IDs so the intended rule is evaluated first |
| Pattern specificity | Make pattern more specific |
| Multiple matches | Review all criteria |