Skip to content

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 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: missing-fields
name: Fehlende Felder melden
template: custom
trigger:
documentType: incoming-invoice
fields: []
start: check
steps:
- 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: rejected

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');
},
});

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

  • Input: vendorName Bürobedarf Schmidt GmbH, invoiceNumber 2026-4711, invoiceDate 2026-10-19, dueDate 2026-11-18, totalGross 342.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: vendorName Bürobedarf Schmidt GmbH, invoiceNumber 2026-4712, invoiceDate null, dueDate null, totalGross 89.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.”
  • Input: vendorName null, invoiceNumber null, invoiceDate null, dueDate null, totalGross null
  • 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.”