Route by amount
The management approves an incoming invoice over €500, the cost center’s responsible person one up to €500. The management’s approval gets a hint why it is theirs.
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: route-by-amountname: Nach Betrag weiterleitentemplate: customtrigger: documentType: incoming-invoicefields: []start: routesteps: - kind: script name: route label: Nach Betrag weiterleiten script: route.ts hook: onDocumentArrived inputs: - kind: field key: totalGross type: money returns: - key: lane type: enumeration values: - management - costCenter branch: lane exits: - value: management next: management - value: costCenter next: costCenter next: costCenter - kind: humanTask name: management label: Freigabe Geschäftsführung taskKind: approve assignees: [] fallback: kind: role role: owner options: excludeRequester: true excludeActorsOfSteps: [] pickFile: false next: approved onRejected: rejected - kind: humanTask name: costCenter label: Freigabe Kostenstelle taskKind: approve assignees: - when: null assignee: kind: costCenterResponsible fallback: kind: role role: Buchhaltung options: excludeRequester: true excludeActorsOfSteps: [] pickFile: false next: approved onRejected: rejected - kind: end name: approved label: Freigegeben outcome: approved - kind: end name: rejected label: Zurückgewiesen outcome: rejectedThe script route.ts
Section titled “The script route.ts”Hook: onDocumentArrived · Inputs: totalGross · Return values: lane (management, costCenter)
import { defineScript, money } from '@acriva/workflow-sdk';
/** Above this gross amount, the management approves. */const THRESHOLD = 500;
export default defineScript({ hook: 'onDocumentArrived', outputs: { lane: ['management', 'costCenter'] }, run(ctx) { const amount = ctx.document.fields.totalGross; // Without an amount the step goes on to its default next step, the cost center's approval. if (amount == null) return; ctx.log('Gross total', money.format(amount)); if (amount > THRESHOLD) { ctx.hint(`Über ${money.format(THRESHOLD)}: Die Geschäftsführung gibt frei.`); return ctx.branch('management'); } return ctx.branch('costCenter'); },});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 €500
Section titled “An invoice over €500”- Input:
totalGross1249.5 - Exit:
management - Changes: hint on the next task: “Über 500,00 €: Die Geschäftsführung gibt frei.”
An invoice of exactly €500
Section titled “An invoice of exactly €500”- Input:
totalGross500 - Exit:
costCenter - Changes: none