Skip to content

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.
  1. Open the approval rule in the level window.
  2. Turn on Script.
  3. If you like, choose an example from the selection list. It appears in the large text field below.
  4. Adjust the script and save.
Approval rule window with the script switch turned on, example selection and script text field

The script is C# code. It can access these objects:

NameContent
irCasethe document with header data and all accounting lines
irItemLinethe accounting line currently being checked
rulethe approval rule itself, including the selected values (for example cost centers)
loggerfor writing log entries from the script
foundMatchtrue if the rule already matches the line based on the selected values

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 as return 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");