Training Guide: Optimizer
This guide shows you how to grade a Unity Script from OnBase Studio, read what it found, and use the suggested rewrite. Allow about 30 minutes. You don't need an OnBase connection: you paste the code, and the review runs in your browser.
Chapter 1: What the Optimizer does
You paste the C# of a Unity Script and the Optimizer gives you three things:
| You get | What it is |
|---|---|
| A grade | A to F with a score out of 100, like a school grade, for how well the script is built |
| Findings | Each problem with its line number, why it matters and how to fix it |
| A rewrite | The script with safe fixes applied, shown as a diff, plus an optional full rewrite by an AI model |
What it reads
It recognizes Workflow, WorkView, Unity Form, scheduled task and event scripts from the interface the class implements. If the code isn't a Unity Script, it says so and grades it anyway.
What it can't do
- It reads the code as text with rules; it can't compile it. It catches patterns, not every bug.
- It doesn't know your OnBase system, so it can't tell whether a keyword type or Document Type name exists.
- A rewrite is a suggestion. Compile it in OnBase Studio and test it in a Test system before production.
Privacy
The review runs in your browser and sends nothing. Only the optional AI rewrite sends code, and only to the provider chosen in Settings: Anthropic with your own key, Microsoft 365 Copilot, or your company's editor back end. If the script contains a password, the button asks you to confirm first.
Chapter 2: Find your way around
Open the Optimizer tab. It has the same three-part layout as the other tabs.
| Area | What's there |
|---|---|
| Left | Saved reviews, with New review. Below them, Try an example: a messy, an average and a well-built script. |
| Middle | Paste a Unity Script: a name and the code. Below it, the findings, worst first. |
| Right | The grade and score, the score for each area, the Rewrite with its diff, and Copy rewritten code, Use as my code and Download report. |
The review updates as you type or paste. Reviews save with your other work.
Chapter 3: Review your first script
- Under Try an example, select Messy invoice approval.
- Look at the grade: F, 19 out of 100.
- Read the first finding, Password or secret in the code. It's critical, costs 20 points, and caps the grade at D whatever the score.
- Select Line 16 on the finding. The line is selected in the code so you can see it.
- Try Average vendor update (a C) and Well-built address cleanup (an A) to see the difference.
Review your own script
- In OnBase Studio, open the Unity Script, select all of its code and copy it.
- In the Optimizer, select New review, give it a name, and paste the code.
- Read the grade and findings.
Chapter 4: How the grade works
Every script starts at 100 and loses points for each finding, within five areas:
| Area | Points | What it covers |
|---|---|---|
| Safety and correctness | 30 | Secrets in code, changing OnBase tables with SQL, SQL injection, locks never released, keyword changes never saved, missing null checks |
| Unity API use | 25 | Its own OnBase connection, direct database reads, repeated lookups, saving inside loops, huge query limits |
| Error handling and logging | 15 | Empty catch blocks, hidden errors, no try/catch, rethrows that lose the stack trace, no Diagnostics Console logging |
| Performance | 15 | Lookups inside loops, Thread.Sleep, building text in loops, forced garbage collection |
| Maintainability | 15 | Hard-coded IDs, paths and email addresses, message boxes, long methods, deep nesting, no header, commented-out code |
An area never goes below zero. A finding that appears on several lines costs more, up to twice its points.
Grades
| Grade | Score |
|---|---|
| A | 90 to 100 |
| B | 80 to 89 |
| C | 70 to 79 |
| D | 60 to 69 |
| F | Below 60 |
Some problems cap the grade whatever the score:
- a password in the code, or changes to OnBase tables with SQL, caps it at D;
- SQL built by joining strings, or a document lock that's never released, caps it at C.
Severities
| Severity | Meaning |
|---|---|
| Critical | Can expose secrets or damage data. Fix before using the script. |
| High | Likely to fail, lock documents or lose changes. |
| Medium | Works, but fragile or slow. |
| Low | Tidiness and good habits. |
| Note | Information only; costs no points, such as a Workflow script that never sets a result. |
Chapter 5: Use the rewrite
The Rewrite shows Safe fixes by default. These only change how the script reports and tidies itself, never what it does:
- rethrows with throw; so the stack trace is kept;
- logs the full exception instead of only its message;
- makes empty catch blocks log the error (they still carry on, as before);
- wraps the main method in try/catch that logs and rethrows, when there was no error handling;
- adds a Started line to the Diagnostics Console when there was no logging;
- adds using System;, a header to fill in, and removes duplicate using lines and trailing spaces.
The pill beside Rewrite, such as C 75 → C 77, shows the grade after the fixes. Still to fix by hand lists what's left: anything that changes behavior, such as moving a lookup out of a loop, is for you to decide.
- Read the diff: green lines are added, red lines removed.
- Select Copy rewritten code and paste it into OnBase Studio, or Use as my code to review it again here.
- Compile and test it in a Test system.
Full rewrite with AI
Select Full rewrite (AI) to have a model restructure the code, such as moving lookups out of loops. It needs an AI model chosen in Settings › AI assistant: Claude with your own API key, Microsoft 365 Copilot with your work account, or a model through your company's editor back end. With the offline assistant, only the safe fixes are available. If the script contains a password, the button asks you to confirm before sending it.
Chapter 6: Share the review
Select Download report to save the review as a web page. It holds the grade, the score for each area, every finding with why it matters and how to fix it, the suggested changes and the rewritten code. Passwords and secrets are masked. Open it in a browser and print to PDF for a code review or change control record.
Chapter 7: Practice
- Open Average vendor update. Fix Lookups inside a loop by hand: move KeywordTypes.Find("Vendor Number") above the foreach and reuse the variable you already have. Watch the Performance score rise.
- Open Messy invoice approval and select Use as my code. Which findings remain, and why couldn't the safe fixes change them?
- Paste one of your own scripts. Before reading the findings, guess its grade.
Troubleshooting
| Problem | Fix |
|---|---|
| "This doesn't look like a Unity Script" | Paste the whole file, including the class line with its interface, such as : IWorkflowScript. |
| A finding doesn't apply to my script | The checks are patterns. Read why it matters and decide; a note in the script's header explaining the choice helps the next reviewer. |
| The safe fixes didn't add try/catch | They only add it when the script has no try at all and its main method receives the Application object. |
| Full rewrite (AI) says it needs a model | Choose a provider in Settings › AI assistant, such as Claude with your own API key, or use the safe fixes. |
| The grade seems harsh | Each finding shows exactly what it cost. Critical problems cap the grade on purpose. |