Business Rules
Verified against source (9)
application/Matrix.csConfig/Matrix.configapplication/AbstractObject.csapplication/BusinessRule.csConfig/ObjectLink.configProperties/Settings.settingsExtensions/AbstractObjectExtensions.csListeners/RuleSetPropertiesListener.csqbo4.Rule/readme.md
Matrices are Matrix records, with MatrixDimension inputs, MatrixMeasure outputs, and MatrixFact cells. Operations follow the standard route pattern: /api/{module}/{operation} runs synchronously, and /api/{module}/queue/{operation} queues the operation for an app server.
Look up a matrix
Section titled “Look up a matrix”Pass the matrix by name (Matrix) or ID (ID or MatrixID), plus one parameter per input. Parameter names are the input names with spaces removed.
GET /api/matrix/lookup?Matrix=Inspection Pricing&State=CA&Client=Acme&OrderAmount=250000&Output=JsonThe first table lists candidate rows, best first. Use the first row only if its MisMatchCount is 0. Each row includes:
| Column | Meaning |
|---|---|
Weight, MatchCount, MisMatchCount |
Total weight of matched inputs, matched cells, and filled cells that didn’t match |
{Output} |
The output’s value, such as Price |
{Output}ID, {Output}Type |
The output’s ID and value type |
{Output}Object, {Output}ObjectID |
For Object outputs, the record the value points to |
Rows are sorted by eligibility (no mismatches first), then by Weight and MatchCount, both descending. Results are paged by RecordStart and DisplaySize (default 25). If an output’s name contains Matrix, the named child matrix is looked up and its outputs are appended to the row. The nesting limit is set by the MatrixRecursion setting (default 16).
To evaluate a record instead of passing inputs:
GET /api/matrix/lookupbyobject?ID=12&Object=Process&ObjectID=1042lookupbyobject requires the matrix ID, plus Object and ObjectID. For each input, QBO evaluates the input’s XPath against the record’s summary XML. If no XPath is set, it looks for //{Input}.
Set fields on a record from a rule set
Section titled “Set fields on a record from a rule set”updatefromrule works on any module where the rules engine extension is installed. It loads the matrix into the in-memory rules engine, finds the best rule for each record, sets fields named like the outputs, and saves.
POST /api/importform/updatefromrule?ID=127&RuleSet=Inspection Pricing| Parameter | Default | Purpose |
|---|---|---|
RuleSet (or RuleSetName, RuleSetMatrix, FromMatrix) |
required | Matrix name |
RuleSetUseSummary |
false |
Also match inputs against the record’s summary XML |
RuleSetThrowIfError |
true |
When false, a failed lookup is swallowed instead of raised |
RuleSetForceDirty |
true |
Save even if no values changed |
Output values can contain {Field} substitutions. On forms (ImportForm), outputs that aren’t columns are merged into the form’s answers.
To apply a rule set automatically, configure a method listener on a module. Use the type qbo4.Rule.Bridge.Listeners.RuleSetPropertiesListener, qbo4.Rule.Bridge and methods such as Insert,Update. The listener fires when the call includes RuleSetMatrix, and saves the record only if a value changed.
Two older equivalents also run on any module. updatefrommatrix?FromMatrix=… sets fields from Matrix.Lookup, and lookupfrommatrix?FromMatrix=… returns each record’s outputs without saving.
Create a record from a matrix
Section titled “Create a record from a matrix”evaluate looks up a matrix against a record, reads a template name (or Object output) from a measure, and creates an instance of that template under the record.
POST /api/process/evaluate?ID=1042&Matrix=Intake Routing&Measure=Workflow&TemplateClass=DecisionTemplateMatrix is required. Measure defaults to the first output. TemplateClass (or Class, ClassName) is used when the output is a plain name rather than an Object. Other parameters are passed to the new record. If the output points to another matrix, evaluation continues there.
Validation rules on save
Section titled “Validation rules on save”AbstractObject.ValidateRules(operation, parameters) runs before inserts, updates, and saves, and before invoked statements and services. It loads the active BusinessRule rows for the record’s table and operation, and caches them for BusinessRuleCacheDuration minutes (default 1440). For each rule:
- Writes
<{Table}BusinessRuleItem>containing the record’s XML and the call’s parameters. - Runs the validator plugin (
RuleValidator: an XSLT stored as a document on the rule). - Treats each
<Exception>in the output as aRuleException, which is thrown and aborts the operation. Each<Warning>raises an alert and the call continues.
The BusinessRuleEnabled setting (default true) turns enforcement on or off for an installation.
Object links
Section titled “Object links”ObjectLink rows join PrimaryObject/PrimaryObjectID to LinkedObject/LinkedObjectID, with ObjectLinkType naming the set. Either side can be bound by PrimaryObjectSubscriberID or LinkedObjectSubscriberID instead of an ID.
POST /api/objectlink/save?PrimaryObject=Organization&PrimaryObjectID=88&LinkedObject=AttachmentTemplate&LinkedObjectID=14&ObjectLinkType=Client LettersPOST /api/objectlink/copyset?OldSet=Client Letters&NewSet=Client Letters 2027POST /api/objectlink/deleteset?Set=Client Letters 2027copyset skips links that already exist in the new set.