Keyform StudioHelpOpen Keyform Studio

Training Guide: SQL

This guide shows you how to turn a question such as "how many document types do we have?" into a read-only SQL query against the OnBase hsi tables, check it, and run it safely. Allow about 40 minutes. To run queries on your own system you'll need read access to the OnBase database, ideally a reporting copy, and a tool such as SQL Server Management Studio or SQL Developer.

Chapter 1: What the SQL tab does

You ask a question in plain English; Keyform Studio picks the matching question type, fills in its settings, and writes a SQL query for the OnBase hsi tables that you can copy and run.

Read-only, always

What you need

ForYou need
Learning and demosNothing: the training connection returns made-up results
Running queries on your systemRead access to the OnBase database, ideally a reporting copy, and SQL Server Management Studio, Azure Data Studio or Oracle SQL Developer
Correct table namesOne run of the name check in Chapter 2, per OnBase system

Chapter 2: Set up for your database

Do this once per OnBase system, or ask your administrator to. Open Settings → SQL.

Database options

SettingChoose
Database platformMicrosoft SQL Server or Oracle, whichever your OnBase uses. Date functions and row limits change to match.
Schemahsi, unless your system uses another
Default maximum rows500 is a safe start; a query never returns more unless you change it
Status value for active documents0. Queries leave out deleted documents unless you untick Only count active documents.
WITH (NOLOCK)On for SQL Server, so reports don't hold up people working in OnBase. Results may include changes still in progress, which is fine for counts.

Check the table and column names

OnBase table and column names are mostly stable, but a few differ between versions. The name check compares Keyform Studio's names with your database's own list, and corrects the obvious differences for you.

  1. Open Settings, select SQL, and find Check the names against your database.
  2. Select Copy query, and run it in SQL Server Management Studio, SQL Developer or a similar tool against the OnBase database. It reads only the database's list of tables and columns, never document data. The query already uses the platform and schema chosen above it, so set those first.
  3. Give Keyform the result, either way:
    • Choose a file. Save the result as a CSV or text file (in SQL Server Management Studio, right-click the results grid and select Save Results As), then choose it under Saved result file. Keyform runs the check as soon as you choose it.
    • Paste. Select the results grid, copy the two columns, table_name and column_name, paste them under Or paste the result, and select Check pasted names.
  4. Read the result:
    • Fixed automatically lists each name Keyform corrected and what it changed it to, for example itemdate → item_date. It only changes a name when your database has exactly one close match: the same name with different underscores or capitals, a name that contains it, or one a letter or two off. The corrected names appear in Tables and columns below. To put them back, select Undo these changes.
    • Still needs you lists names with no single close match, either none or several. Find the right one in your results and type it into Tables and columns.
  5. Run the check again until it reports that all names matched.

The file is read in your browser and isn't uploaded anywhere. Keyform keeps only the corrected names, with your SQL settings. Corrected names stop showing the "check these column names" warning.

Columns marked (check) are the ones most likely to differ, such as the date a document entered a Workflow queue.

Chapter 3: Ask your first question

  1. Open the SQL tab.
  2. In What are you looking for?, type: How many document types do we have?
  3. Select Write query. The assistant reports Picked “Document Types”.
  4. Look at the middle panel: the question type is Document Types, and Show is set to How many there are.
  5. Look at the right panel: the SQL counts the rows in hsi.doctype.
  6. Select Run on training data. The result is one row: the number of Document Types in the training system, 8.

Questions it understands

The assistant matches your question to one of 15 question types and fills in what it can find: a Document Type, a keyword and value, a date range, a user or group, a Life Cycle, a number of days, or a row limit. Some examples:

Tips

Chapter 4: Adjust a query

The settings in the middle panel are the query. Change any of them and the SQL updates at once; you don't need to ask again.

  1. Ask: How many invoices were stored last month?
  2. The question type is Count documents, with Document Type set to AP - Invoice and Date range to Last month.
  3. Change Date range to Last N days and Number of days to 90. The SQL's date condition changes.
  4. Change Date to use to Document date. The query now filters on the invoice's own date instead of the date it was stored.
  5. Set Document Type to All Document Types. The Document Type condition disappears.

Common settings

SettingWhat it changes
Document TypeLimits the query to one Document Type, or all
Date rangeAny time, today, yesterday, last N days, this or last month, this year, last 12 months, or between two dates
Date to useDate stored, or the document date
Keyword Type and valueFor Find documents by keyword value: which keyword, the test (equals, contains, starts with, greater than…) and the value
Group byDay, month or year for documents over time; Disk Group or File Format for storage
Maximum rowsCaps the result; empty uses the default from Settings

You can also pick a question type directly from Question types on the left, then fill in its settings yourself.

Chapter 5: Read the SQL before you run it

Every query explains itself. Read the four parts of the right panel before you copy anything.

  1. The comment lines at the top repeat your question, say in plain English what the query does, and name the database platform.
  2. The SQL itself. Look at the WHERE lines: they hold every filter, such as the Document Type number, the date range and i.status = 0 for active documents.
  3. What it returns says what each row means, for example "One row per Document Type with its document count".
  4. Tables used lists each hsi table with a plain name, such as hsi.itemdata (Documents).

An amber Check these column names box appears when the query uses a column whose name can differ by OnBase version. Confirm it with the name check in Chapter 2 before you trust the result.

Example: documents per Document Type this year, on SQL Server

SELECT TOP 500 dt.itemtypename AS document_type,
       COUNT(*) AS documents
FROM hsi.itemdata i WITH (NOLOCK)
JOIN hsi.doctype dt WITH (NOLOCK) ON dt.itemtypenum = i.itemtypenum
WHERE i.status = 0
  AND i.datestored >= DATEFROMPARTS(YEAR(GETDATE()), 1, 1)
GROUP BY dt.itemtypename
ORDER BY documents DESC;

On Oracle the same question uses TRUNC(SYSDATE, 'YYYY') for the start of the year and FETCH FIRST 500 ROWS ONLY for the row limit, with no NOLOCK.

Chapter 6: Run it

On training data

Select Run on training data. A results table appears under the SQL, marked Sample results from the training instance. The numbers are made up but realistic, so you can practise and record demos without touching a real system.

On your OnBase database

  1. Select Copy SQL. If the browser blocks it, the SQL is selected; press Ctrl+C.
  2. Open SQL Server Management Studio, Azure Data Studio or Oracle SQL Developer.
  3. Connect to a reporting copy of the OnBase database if your company has one; otherwise use an account with read-only access.
  4. Paste the query and run it.
  5. Compare the result with what you expected. For a count, a quick check in the OnBase client, such as a document search, is a good sanity test.

Good habits

Chapter 7: Question types reference

Question typeAnswersExample question
Count documentsHow many documents matchHow many invoices were stored last month?
List documentsThe newest matching documents with handle, name and datesShow me the newest work order requests
Documents per Document TypeWhich Document Types have the most documentsDocuments per document type this year
Documents stored over timeDocuments per day, month or yearInvoices stored per month this year
Documents stored per userWho stored the most documentsWho scanned the most documents in the last 30 days?
Find documents by keyword valueDocuments whose keyword matches a valueInvoices with Invoice Amount over 10000
History of a documentThe transaction log for one documentHistory of document 104231
Document TypesHow many there are, or the list, optionally by groupHow many claims document types are there?
Keyword Types on a Document TypeThe keywords assigned to one Document TypeWhich keywords are on AP - Invoice?
Document Types with no documentsUnused Document Types, for clean-upDocument types with no documents
Storage by Disk Group or File FormatDocuments and files per Disk Group or File FormatStorage by disk group
UsersHow many users, or the list, by status and groupList disabled users
User Groups and membersEach User Group with its member countList user groups
What a user didOne user's transaction log entriesWhat did SCHEN do yesterday?
Documents in Workflow queuesDocuments per queue and the oldest wait in daysDocuments in workflow queues waiting more than 3 days

Chapter 8: Save and reuse queries

Every query you write is kept under Saved queries on the left, named after your question, and saved to your account automatically.

  1. Select a saved query to open it. Its settings and SQL come back exactly as you left them.
  2. Rename it in Query name, for example Monthly invoice volume.
  3. To make a variation, select New query, ask a similar question, and adjust the settings.
  4. Delete query removes it, after you select it a second time to confirm.

The SQL is regenerated from the saved settings each time, so if you later change Settings → SQL, such as the platform or a corrected column name, every saved query uses the new setting.

Chapter 9: Troubleshooting

ProblemLikely causeFix
"Couldn't match that to a question type"The question doesn't resemble any of the 15 typesReword it like an example in Chapter 7, or pick a question type on the left
The wrong question type was pickedTwo types share words, for example users and groupsPick the right type on the left and set it up yourself
Invalid object name, or table or view does not existSchema or table name differsCheck Schema and run the name check in Settings → SQL
Invalid column nameA column differs in your OnBase versionRun the name check and correct the column under Tables and columns
The query returns no rowsThe filters are too narrow, or the keyword values live in a separate value tableWiden the date range, check the Document Type, and read the note in What it returns
Permission deniedYour database account can't read the hsi tablesAsk your database administrator for read-only access, ideally on a reporting copy
The query is slowIt covers many years of documentsNarrow the date range, run it out of hours, or use a reporting copy
Counts look too highDeleted documents are includedTurn on Only count active documents and check the active status value

Chapter 10: Practice exercises

Answer each question on the training connection, then on your own system if you have access.