Report missing fields
When an incoming invoice lacks its invoice number, invoice date, due date or gross total, the script notifies accounting and names the missing details. The invoice gets the tag “Prüfen” and goes to be completed first, then to the approval. With no script, the card Check the mandatory details checks these details but the due date, and more mandatory details, and tells the next task what is missing.
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: missing-fieldsname: Fehlende Felder meldentemplate: customtrigger: documentType: incoming-invoicefields: []start: checksteps: - kind: script name: check label: Pflichtangaben prüfen script: check.ts hook: onDocumentArrived inputs: - kind: field key: vendorName type: text - kind: field key: invoiceNumber type: text - kind: field key: invoiceDate type: date - kind: field key: dueDate type: date - kind: field key: totalGross type: money returns: - key: details type: enumeration values: - complete - missing branch: details exits: - value: complete next: approve - value: missing next: fix next: approve - kind: humanTask name: fix label: Fehlende Angaben ergänzen taskKind: fix assignees: - when: null assignee: kind: role role: Buchhaltung fallback: kind: role role: Buchhaltung options: excludeRequester: false excludeActorsOfSteps: [] pickFile: false next: approve - kind: humanTask name: approve label: Freigabe 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 check.ts
Section titled “The script check.ts”Hook: onDocumentArrived · Inputs: vendorName, invoiceNumber, invoiceDate, dueDate, totalGross · Return values: details (complete, missing)
import { defineScript } from '@acriva/workflow-sdk';
export default defineScript({ hook: 'onDocumentArrived', outputs: { details: ['complete', 'missing'] }, run(ctx) { const { vendorName, invoiceNumber, invoiceDate, dueDate, totalGross } = ctx.document.fields; // The details an invoice needs before it is approved, with the name the notice gives each. const required = [ { label: 'Rechnungsnummer', value: invoiceNumber }, { label: 'Rechnungsdatum', value: invoiceDate }, { label: 'Fälligkeitsdatum', value: dueDate }, { label: 'Bruttobetrag', value: totalGross }, ]; const missing = required.filter((detail) => detail.value == null).map((detail) => detail.label); if (missing.length === 0) return ctx.branch('complete');
const invoice = vendorName == null ? 'Einer Eingangsrechnung' : `Der Rechnung von ${vendorName}`; ctx.notify({ to: [{ role: 'Buchhaltung' }], text: `${invoice} fehlen diese Angaben: ${missing.join(', ')}. Bitte ergänzen Sie sie.`, }); ctx.addTag('Prüfen'); ctx.hint(`Es fehlen: ${missing.join(', ')}.`); return ctx.branch('missing'); },});What it does
Section titled “What it does”A test runs each of these cases in the sandbox and compares the result.
A complete invoice
Section titled “A complete invoice”- Input:
vendorNameBürobedarf Schmidt GmbH,invoiceNumber2026-4711,invoiceDate2026-10-19,dueDate2026-11-18,totalGross342.72 - Exit:
complete - Changes: none
The invoice date and the due date are missing
Section titled “The invoice date and the due date are missing”- Input:
vendorNameBürobedarf Schmidt GmbH,invoiceNumber2026-4712,invoiceDatenull,dueDatenull,totalGross89.9 - Exit:
missing - Changes: notification to the role
Buchhaltung: “Der Rechnung von Bürobedarf Schmidt GmbH fehlen diese Angaben: Rechnungsdatum, Fälligkeitsdatum. Bitte ergänzen Sie sie.”; tag “Prüfen”; hint on the next task: “Es fehlen: Rechnungsdatum, Fälligkeitsdatum.”
An invoice where nothing was recognized
Section titled “An invoice where nothing was recognized”- Input:
vendorNamenull,invoiceNumbernull,invoiceDatenull,dueDatenull,totalGrossnull - Exit:
missing - Changes: notification to the role
Buchhaltung: “Einer Eingangsrechnung fehlen diese Angaben: Rechnungsnummer, Rechnungsdatum, Fälligkeitsdatum, Bruttobetrag. Bitte ergänzen Sie sie.”; tag “Prüfen”; hint on the next task: “Es fehlen: Rechnungsnummer, Rechnungsdatum, Fälligkeitsdatum, Bruttobetrag.”