Skip to content

Four eyes above a threshold

The cost center’s responsible person approves every incoming invoice first. Above a gross total of €5,000, the management approves it a second time, and a different person must do so. The script points this out already on the first approval.

The workflow starts for every document of the type incoming-invoice. Its file workflow.yaml:

$schema: 'https://docs.acriva.de/schemas/workflow.schema.json'
format: 1
schemaVersion: 4
sdk: '1.0.0'
key: four-eyes-threshold
name: Vier Augen ab Schwellenwert
template: custom
trigger:
documentType: incoming-invoice
fields: []
start: announce
steps:
- kind: script
name: announce
label: Zweite Freigabe ankündigen
script: announce.ts
hook: beforeApproval
inputs:
- kind: field
key: totalGross
type: money
returns: []
exits: []
next: firstApproval
- kind: humanTask
name: firstApproval
label: Freigabe Kostenstelle
taskKind: approve
assignees:
- when: null
assignee:
kind: costCenterResponsible
fallback:
kind: role
role: Buchhaltung
options:
excludeRequester: true
excludeActorsOfSteps: []
pickFile: false
next: overThreshold
onRejected: rejected
- kind: condition
name: overThreshold
label: Über 5.000 €?
branches:
- when:
kind: compare
field: totalGross
operator: greaterThan
constants:
- '5000'
next: secondApproval
default: approved
- kind: humanTask
name: secondApproval
label: Zweite Freigabe Geschäftsführung
taskKind: approve
assignees:
- when: null
assignee:
kind: role
role: Geschäftsführung
fallback:
kind: role
role: owner
options:
excludeRequester: true
excludeActorsOfSteps:
- firstApproval
pickFile: false
next: approved
onRejected: rejected
- kind: end
name: approved
label: Freigegeben
outcome: approved
- kind: end
name: rejected
label: Zurückgewiesen
outcome: rejected

Hook: beforeApproval · Inputs: totalGross · Return values: none

import { defineScript, money } from '@acriva/workflow-sdk';
/** Above this gross amount a second approval follows; the workflow's condition step "Über 5.000 €?" uses the same value. */
const THRESHOLD = 5000;
export default defineScript({
hook: 'beforeApproval',
run(ctx) {
const amount = ctx.document.fields.totalGross;
if (amount == null || amount <= THRESHOLD) return;
// Before an approval a script only reads; its one effect is a hint on the approval's task.
ctx.hint(
`Über ${money.format(THRESHOLD)}: Nach Ihrer Freigabe gibt die Geschäftsführung die Rechnung ein zweites Mal frei.`,
);
},
});

A test runs each of these cases in the sandbox and compares the result.

  • Input: totalGross null
  • Exit: the default next step
  • Changes: none
  • Input: totalGross 12480
  • Exit: the default next step
  • Changes: hint on the next task: “Über 5.000,00 €: Nach Ihrer Freigabe gibt die Geschäftsführung die Rechnung ein zweites Mal frei.”
  • Input: totalGross 5000
  • Exit: the default next step
  • Changes: none