Approval scripts
Whether an approval level applies to an accounting line is determined by its approval rules (see Approvals). Normally a rule compares a property such as cost center, account or project. For more complex conditions you can store a script on a rule. invoiceR runs it for each accounting line and uses the result to decide whether the rule applies.
Typical examples: the level should apply if …
- a specific cost center and a specific account are used,
- the cost center starts with 99,
- the supplier name contains a specific word,
- a specific VAT code is used.
Turning on a script
Section titled “Turning on a script”- Open the approval rule in the level window.
- Turn on Script.
- If you like, choose an example from the selection list. It appears in the large text field below.
- Adjust the script and save.
What the script can use
Section titled “What the script can use”The script is C# code. It can access these objects:
| Name | Content |
|---|---|
irCase | the document with header data and all accounting lines |
irItemLine | the accounting line currently being checked |
rule | the approval rule itself, including the selected values (for example cost centers) |
logger | for writing log entries from the script |
foundMatch | true if the rule already matches the line based on the selected values |
Return value
Section titled “Return value”If a script is stored, its return value decides:
true: the rule applies and the level requests its approvals.false: the rule does not apply.null: the script does not decide; what counts is whether the selected values match.return null;therefore has the same effect asreturn foundMatch;.
Example: the rule should only apply if the selected cost center matches and the account starts with 6.
if (!foundMatch){ return false;}
var accountNumber = irItemLine.Account?.Number ?? "";return accountNumber.StartsWith("6");