A database lookup connects DocView Capture to your own data, such as your ERP's supplier or purchase order tables. Lookups can:
- check that a value exists, for example a purchase order number,
- fill other fields from the matching row, for example the supplier's name and ID from its VAT number,
- suggest values while an operator types, and
- act as a master data list that finders match documents against, even with OCR mistakes.
Lookups query SQL Server. They are set up once for the whole system and then used by fields and finders in any Batch Setup.
Before you start: store the connection string
Lookups never hold a password themselves. The connection string is stored as a secret.
- Go to Settings and open the secrets.
- Add a secret with the SQL Server connection string, for example named
lookup.erp.
Tip: Use a database account that can only read the tables you need. Lookups only ever run the query you write.
Create a lookup
- Go to Administration › Batch Settings › Lookups. The page is called Database lookups.
- Click New lookup.
- Enter a Name, for example
Suppliers by VAT number. - Choose the Connection string secret.
- Write the Query (see below).
- Choose what the lookup is for under Use.
- Click Save lookup.
- Type a Test value next to the lookup and click Test to see the rows it returns.
Write the query
Use @value for the field's value. Other fields of the document can be used as @FieldName. Values are always passed as parameters, never pasted into the SQL, so the query is safe from SQL injection.
SELECT VendorName, VendorId FROM Vendors WHERE VatNumber = @value
A query can use another field too:
SELECT PoNumber, Amount FROM PurchaseOrders
WHERE PoNumber = @value AND SupplierId = @SupplierId
Queries have a time-out of 5 seconds. Keep them fast: filter on indexed columns.
Lookup uses
| Use | What it does |
|---|---|
| Validate — the value must exist | The field fails validation when the query returns no row. |
| Auto-fill — copy columns into fields with the same name | Checks the value and copies the first row's columns into fields. |
| Suggest — offer values from the first column while typing | Shows up to 10 suggestions from the first column as the operator types. |
| Master data list — for lookup finders (fuzzy match, e.g. all suppliers); no @value needed | Returns a whole list for fuzzy matching by finders. |
Empty field values are not looked up.
Any lookup can also be opened by a lookup button on a designed form, where the operator searches its rows by column and picks one to fill several fields. See Screen designer.
Use a lookup on a field
- Open the Batch Setup, go to Document classes & fields and open the field.
- Under Extraction, choose the Database lookup.
- Under Lookup fills these fields, map lookup columns to fields, one per line, as
column = field:
VendorName = Supplier
VendorId = SupplierId
Columns named like a field fill it anyway. The map is used when a row is found and when the operator picks a row from the list.
- Click Save field.
The operator's pick list
Fields with a lookup get a search button on the Index / Validate screen. Operators press F4 or click the button to open a searchable list of the lookup's rows. Choosing a row fills every mapped field of the document, or of the table row.
Master data and fuzzy matching
OCR is rarely perfect. A supplier name may come out as "Acme Industrles Ltd" or a VAT number with a space in the wrong place. A master data list lets DocView find the right supplier anyway.
- Create a lookup with Use set to Master data list. The query returns all rows and needs no
@value:
SELECT SupplierId, Name, VatNumber, Postcode FROM Suppliers WHERE Active = 1
- On the Finders tab, add a finder with the method Database lookup (fuzzy) and choose this lookup.
- Set Column to match on the document (for example
Name) and Also match these columns (for exampleVatNumberandPostcode). - Set Value to return, for example
SupplierId. - List the Other columns fields can use, then connect fields to
Supplier.VatNumber,Supplier.Nameand so on. - Test on your samples.
Minimum similarity (default 0.85) sets how many OCR mistakes are allowed. See Finders and zones.
A master data list may hold up to 50,000 rows. DocView keeps it in memory for 10 minutes and reloads it at once when you change the lookup. For larger tables, narrow the list in the query, for example to active suppliers only.
Tip: Matching on several columns makes results far more reliable. A supplier name alone can be ambiguous; name plus VAT number or postcode rarely is.
Lookups and exported Batch Setups
Batch Setup files refer to lookups by name. When you import a Batch Setup on another system, create lookups with the same names there first, and fields pick them up automatically. See Import and export Batch Setups.
Troubleshooting
| Problem | What to check |
|---|---|
| "Secret … was not found" | The secret name on the lookup matches a secret under Settings. |
| "Lookup query failed" | Test the query in SQL Server Management Studio with a real value. |
| Every value fails validation | Formatting: remove spaces or prefixes with a formatter before the lookup. |
| The fuzzy finder picks the wrong row | Add more columns to match, or raise Minimum similarity. |