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
Section titled “The workflow”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: 1schemaVersion: 4sdk: '1.0.0'key: four-eyes-thresholdname: Vier Augen ab Schwellenwerttemplate: customtrigger: documentType: incoming-invoicefields: []start: announcesteps: - 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: rejectedThe script announce.ts
Section titled “The script announce.ts”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.`, ); },});What it does
Section titled “What it does”A test runs each of these cases in the sandbox and compares the result.
An invoice without a gross total
Section titled “An invoice without a gross total”- Input:
totalGrossnull - Exit: the default next step
- Changes: none
An invoice over €5,000
Section titled “An invoice over €5,000”- Input:
totalGross12480 - 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.”
An invoice of exactly €5,000
Section titled “An invoice of exactly €5,000”- Input:
totalGross5000 - Exit: the default next step
- Changes: none