Zum Inhalt springen

Nach Dokumenttyp aufteilen

Ein Workflow ohne Dokumenttyp, den Sie von Hand auf einem beliebigen Dokument starten: Eine Eingangsrechnung gibt die Buchhaltung frei, einen Vertrag prüft die Geschäftsführung, und jedes andere Dokument nimmt die Buchhaltung zur Kenntnis. Weil der Workflow keinen Dokumenttyp hat, liest das Skript keine Felder, nur den Typ des Dokuments.

Der Workflow startet von Hand. Seine Datei workflow.yaml:

$schema: 'https://docs.acriva.de/schemas/workflow.schema.json'
format: 1
schemaVersion: 4
sdk: '1.0.0'
key: split-by-document-type
name: Nach Dokumenttyp aufteilen
template: custom
trigger: {}
fields: []
start: split
steps:
- kind: script
name: split
label: Nach Dokumenttyp aufteilen
script: split.ts
hook: onDocumentArrived
inputs: []
returns:
- key: kind
type: enumeration
values:
- invoice
- contract
- other
branch: kind
exits:
- value: invoice
next: invoice
- value: contract
next: contract
- value: other
next: other
next: other
- kind: humanTask
name: invoice
label: Freigabe Rechnung
taskKind: approve
assignees: []
fallback:
kind: role
role: Buchhaltung
options:
excludeRequester: true
excludeActorsOfSteps: []
pickFile: false
next: approved
onRejected: rejected
- kind: humanTask
name: contract
label: Prüfung Vertrag
taskKind: review
assignees: []
fallback:
kind: role
role: Geschäftsführung
options:
excludeRequester: false
excludeActorsOfSteps: []
pickFile: false
next: approved
onRejected: rejected
- kind: humanTask
name: other
label: Kenntnisnahme
taskKind: acknowledge
assignees: []
fallback:
kind: role
role: Buchhaltung
options:
excludeRequester: false
excludeActorsOfSteps: []
pickFile: false
next: done
- kind: end
name: approved
label: Freigegeben
outcome: approved
- kind: end
name: rejected
label: Zurückgewiesen
outcome: rejected
- kind: end
name: done
label: Erledigt
outcome: completed

Hook: onDocumentArrived · Eingaben: keine · Rückgaben: kind (invoice, contract, other)

import { defineScript } from '@acriva/workflow-sdk';
export default defineScript({
hook: 'onDocumentArrived',
outputs: { kind: ['invoice', 'contract', 'other'] },
run(ctx) {
// The workflow has no document type, so it starts by hand on any document and reads no fields, only the type.
switch (ctx.document.type) {
case 'incoming-invoice':
return ctx.branch('invoice');
case 'contract':
return ctx.branch('contract');
default:
// Every other type, also one the workspace adds later.
ctx.log('Document type', ctx.document.type);
return ctx.branch('other');
}
},
});

Ein Test führt jeden dieser Fälle in der Sandbox aus und vergleicht das Ergebnis.

  • Eingabe: keine
  • Ausgang: contract
  • Änderungen: keine
  • Eingabe: keine
  • Ausgang: other
  • Änderungen: keine
  • Eingabe: keine
  • Ausgang: invoice
  • Änderungen: keine