Training Guide: Scripts
This guide shows you how to create Workflow, Unity Form and WorkView scripts from a plain-English description, check the C# they produce, and put them into OnBase Studio. Allow about an hour, plus time in your OnBase Test system. You don't need to write C#, but you do need rights to create Unity Scripts in OnBase Studio for Chapter 8.
Chapter 1: What Unity Scripts are
Unity Scripts are small C# programs that OnBase runs at a set moment: when a document reaches a Workflow queue, when someone presses a button on a Unity Form, or when a WorkView action runs. Keyform Studio writes them from steps you choose or describe.
| Script type | Runs when | Works on | Typical uses |
|---|---|---|---|
| Workflow | A Workflow action or rule runs it | A document's keywords | Check required keywords, clean up values, add a note, decide a rule's true or false result |
| Unity Form | Someone triggers a custom action on a Unity Form | The form's fields | Fill fields from a database lookup, stamp a date, check required fields |
| WorkView | A WorkView action runs it | A WorkView object's attributes | Set a status when a condition is met, stamp a review date, check required attributes |
Every script is a list of steps, run in order from top to bottom. Each step is one job, such as "Check required keywords" or "Set Status to Needs Review when Risk Score is over 70".
Chapter 2: Tour of the Scripts tab
The Scripts tab has your scripts and the step list on the left, the script you're working on in the middle, and its C# code on the right.
| Area | What's there |
|---|---|
| Unity Scripts | Your saved scripts, with their type and number of steps. New script starts another. |
| Add a step | The steps available for the current script type. Select one to add it at the end. |
| Script settings | Script type (Workflow, Unity Form, WorkView), name, where names come from, what happens on an error, and logging |
| Describe what the script should do | The AI assistant box. Draft steps turns your description into steps. |
| Steps | Each step as a card: its number, a one-line summary, its settings, and ↑, ↓ and Delete |
| Code | The C# file, its problems and warnings, the review checkbox and Copy C# |
The training connection includes three sample scripts, one of each type. If you don't see them, add them from Settings → Connections → Training → Add the sample scripts.
Chapter 3: Create a Workflow script with the assistant
You'll create a script that checks new invoices and flags large ones for manager approval.
Set up the script
- Select New script. It starts as a Workflow script.
- Name it Invoice Intake Check. The class name under the settings updates to
InvoiceIntakeCheck. - In Keywords from Document Type, choose AP - Invoice.
- Leave If something goes wrong as Stop the action and show the error, and keep logging on.
Describe it
Type this into Describe what the script should do, one instruction per sentence:
Make sure Vendor Name, Invoice Number and Invoice Amount are filled in. Trim and uppercase Vendor Name. Add a note saying "Checked by workflow: {Vendor Name} invoice {Invoice Number}". If Invoice Amount is greater than 10000, return true.
Select Draft steps. The assistant adds four steps and reports Drafted 4 steps.
Check the draft
- Read each step card. Under each one, From your description shows the sentence it came from.
- Read any amber notes under the draft summary, such as a step that needs a value you didn't give.
- Read any sentence listed as Couldn't turn this into a step, and rephrase it like the examples under What it understands.
Writing descriptions that work
- One instruction per sentence, ending with a full stop.
- Use the keyword names as they appear in the step settings.
- Put note text and exact values in double quotes.
- Use
{Keyword Name}inside quotes to insert a value, and{Today}for today's date.
If you draft again, the new steps replace the existing ones; the button asks you to confirm first.
Chapter 4: Add and edit steps yourself
You can build a whole script from the Add a step list, or adjust what the assistant drafted.
- In Add a step, select Set a keyword. A new step card appears at the end.
- Choose Due Date in Keyword to set, and Today's date in New value.
- Use ↑ to move it above the comparison step, so the comparison stays last.
- On step 1, select PO Number among the keyword chips to add it to the required list. The number on each chip is its order.
A step with a missing setting gets a red border, and the Code panel lists it as a problem.
The step catalogue
| Step | What it does | Workflow | Unity Form | WorkView |
|---|---|---|---|---|
| Check required | Fails the rule (Workflow) or stops with a "Please complete" message if any listed value is blank | Yes | Yes | Yes |
| Compare a keyword | Sets the rule's true or false result | Yes | No | No |
| Set a value | Sets text (with placeholders), today's date, or a session property | Yes | Yes | Yes |
| Set a value when a condition is met | Tests one value, then sets another | Yes | Yes | Yes |
| Clean up a value | Trims, collapses spaces, changes letter case | Yes | Yes | Yes |
| Combine values | Joins several values with a separator into another | Yes | Yes | Yes |
| Fill from a database | Runs a SQL query with values from the script and copies columns back | Yes | Yes | Yes |
| Send to a web service | Posts chosen values as JSON to a URL | Yes | Yes | Yes |
| Add a note | Adds a note of a chosen Note Type, with placeholders | Yes | No | No |
| Save for later | Stores a keyword in a session property for later Workflow actions | Yes | No | No |
When several Workflow steps set the rule result, only the last one counts; the checks warn you about it.
Chapter 5: Read the generated C#
The Code panel updates with every change. You don't need to write C#, but you should be able to find each part and confirm it does what the steps say.
| Part | Where | What to check |
|---|---|---|
| Header comment | Top | The script name, type, Document Type, and What it does: one line per step in plain English |
using lines | Below the header | Libraries the script needs. A web service step adds System.Net.Http; a database step adds System.Data.Odbc. |
| Class line | public class InvoiceIntakeCheck : IWorkflowScript | The class name and the interface OnBase calls |
| Entry method | OnWorkflowScriptExecute(...) | Where OnBase starts the script; it picks up the document being processed |
| Steps | Inside try { ... }, each under // Step 1: ... | One block per step card, in the same order |
| Error handling | catch (Exception ex) | Writes the error to the Diagnostics Console, then stops or carries on as you chose |
| Helpers | Bottom | Shared code for reading and setting keywords, filling placeholders, and logging |
Before you copy
- Clear every Problem listed above the code.
- Read every Warning and decide. The "rule result" warning is expected in Chapter 3's script, because the required check and the comparison both set it and you want the comparison to decide.
- Tick I've read this script and will test it in a Test environment. Copy C# becomes available.
- Select Copy C#. If the browser blocks it, the code is selected; press Ctrl+C.
Any change to the script clears the tick, so the copied code always matches what you reviewed.
Chapter 6: Unity Form scripts
A Unity Form script runs when someone triggers a custom action on a Unity Form, such as a Look up vendor button. You'll build one that fills the vendor's name and email from a database.
- Select New script, then Unity Form under Script type.
- Name it Vendor Lookup.
- In Unity Form field IDs, paste the IDs of the form's fields, separated by commas:
VendorNumber, VendorName, VendorEmail, RequestDate, Notes. Copy the real IDs from the Unity Forms designer; they're case-sensitive. - Describe it:
Make sure VendorNumber is filled in. Look up VendorName and VendorEmail from the database using VendorNumber. Set RequestDate to today.
- Select Draft steps. Three steps appear, with a note on the database step.
- Open the Fill fields from a database step and finish it:
- Connection string setting: the name of the configuration item that holds the ODBC connection string, usually set up by your OnBase administrator. The default is
ODBCConnectionString. - SQL query: replace
your_tablewith the real table, for exampleSELECT vendor_name, vendor_email FROM vendors WHERE vendor_number = ?. Each?is filled by a field you pick, in order. - Columns to copy: one line per column,
column = FieldID, for examplevendor_name = VendorName.
- Connection string setting: the name of the configuration item that holds the ODBC connection string, usually set up by your OnBase administrator. The default is
- Clear the checks, review, and copy the C#.
In a Unity Form script, a failed required check stops the action with a message such as "Please complete: VendorNumber". Workflow-only steps, such as adding a note, aren't offered; the assistant tells you if you ask for one.
Chapter 7: WorkView scripts
A WorkView script runs from a WorkView action and changes the attributes of the object it runs on. You'll build one that reviews a new vendor.
- Select New script, then WorkView under Script type.
- Name it Vendor Review.
- In WorkView application and class, choose Vendor Management / Vendor. Its attributes appear in the step pickers.
- Describe it:
Make sure Vendor Name, Tax ID and Email are filled in. If Risk Score is greater than 70, set Status to "Needs Review". Set Reviewed Date to today.
- Select Draft steps and check the three steps. You can write attribute names with spaces (Risk Score) or without (RiskScore); the assistant matches either.
- Open the Set an attribute when a condition is met step: the test is RiskScore is greater than 70, the attribute to set is Status, and the new value is Needs Review.
- Clear the checks, review and copy the C#.
The WorkView entry-point names aren't publicly documented for every OnBase version. The note under the code says so: compile it in a Test system first and use Chapter 9 if OnBase Studio reports a name it doesn't know.
Chapter 8: Put a script into OnBase Studio
OnBase Studio is where Unity Scripts are stored, compiled and attached. Menu names vary by version, so follow your version's OnBase Studio documentation alongside these steps, in a Test system.
- Open OnBase Studio and connect to your Test repository.
- Create a new Unity Script, named the same as the class, for example
InvoiceIntakeCheck. - Replace the starter code Studio creates with the code you copied from Keyform Studio.
- Add references the header comment asks for:
System.Net.Httpfor a web service step,System.Datafor a database step. - Compile, or build, the script. If it fails, go to Chapter 9.
- Save and check the script into the repository.
- Attach it where it should run:
| Script type | Attach it to |
|---|---|
| Workflow | A Workflow action or rule that runs a Unity Script, in the queue where it should run |
| Unity Form | A custom action on the Unity Form, for example on a button |
| WorkView | A WorkView action of the Execute Unity Script kind, on the class |
- Run it on a test document, form or object, then open the Diagnostics Console to read its log lines, which start with the class name in brackets.
Chapter 9: Fix compile errors
Most compile errors from generated scripts come from one cause: a name in the Unity API that differs in your OnBase version. Fix the name once in Keyform Studio and every script uses the fix.
| Error in OnBase Studio | Where to fix it |
|---|---|
The type or namespace IWorkViewScript (or another interface) could not be found | Settings → Script API names → Interface for that script type |
| The script doesn't implement a member, or the method isn't called | Method for that script type |
WorkViewEventArgs (or another arguments type) could not be found | Event arguments type |
args.Object (or args.FormInstance) doesn't exist | Object the script works on |
System.Net.Http or OdbcConnection not found | Add the reference in OnBase Studio (Chapter 8, step 4) |
A member such as AllFields or CreateFormModifier doesn't exist | A helper in the generated code; send the error to your Keyform Studio administrator so the template can be corrected |
Correcting an API name
- Find the correct name in your Hyland Unity API documentation, or in a working script your team already has.
- Open Settings → Script API names.
- Change the field for that script type. It saves as you type.
- Back on the Scripts tab, review the code again and copy it.
- Paste it into OnBase Studio and compile again.
Reset to defaults on the same page puts the original names back.
Chapter 10: Practice exercises
Do one script of each type on your own, then check it against its list.
Exercise 1: Workflow, claim triage
On CLM - First Notice of Loss: make sure Policy Number and Claimant Name are filled in; uppercase Policy Number; if Estimated Amount is greater than 25000, return true.
Exercise 2: Unity Form, request defaults
With the field IDs RequestedBy, RequestDate, Department, Notes: set RequestDate to today; if Department is "IT", set Notes to "Route to the IT team".
Exercise 3: WorkView, contract expiry
On Vendor Management / Contract: make sure Contract Number and End Date are filled in; if Contract Value is greater than 50000, set Owner to "Legal".
When you're done