Zum Inhalt springen

Nach Lieferant weiterleiten

Rechnungen von IT-Lieferanten wie Telekom oder Dell gibt die IT frei, alle anderen die Kostenstellenverantwortung. Die Liste der IT-Lieferanten steht im Skript, und die Freigabe der IT bekommt einen Hinweis, warum sie sie bekommt.

Der Workflow startet für jedes Dokument vom Typ incoming-invoice. Seine Datei workflow.yaml:

$schema: 'https://docs.acriva.de/schemas/workflow.schema.json'
format: 1
schemaVersion: 4
sdk: '1.0.0'
key: route-by-vendor
name: Nach Lieferant weiterleiten
template: custom
trigger:
documentType: incoming-invoice
fields: []
start: route
steps:
- kind: script
name: route
label: Nach Lieferant weiterleiten
script: route.ts
hook: onDocumentArrived
inputs:
- kind: field
key: vendorName
type: text
returns:
- key: lane
type: enumeration
values:
- it
- standard
branch: lane
exits:
- value: it
next: itApproval
- value: standard
next: costCenter
next: costCenter
- kind: humanTask
name: itApproval
label: Freigabe IT
taskKind: approve
assignees:
- when: null
assignee:
kind: role
role: IT
fallback:
kind: role
role: Buchhaltung
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: rejected

Hook: onDocumentArrived · Eingaben: vendorName · Rückgaben: lane (it, standard)

import { defineScript } from '@acriva/workflow-sdk';
/** The vendors of hardware, software and telephony; a vendor matches when its name starts with an entry, in any case. */
const IT_VENDORS: readonly string[] = ['Telekom', 'Dell', 'Microsoft', 'DATEV', 'Vodafone'];
export default defineScript({
hook: 'onDocumentArrived',
outputs: { lane: ['it', 'standard'] },
run(ctx) {
const vendor = ctx.document.fields.vendorName;
// Without a vendor the step goes on to its default next step, the cost center's approval.
if (vendor == null) return;
const name = vendor.toLowerCase();
const itVendor = IT_VENDORS.find((entry) => name.startsWith(entry.toLowerCase()));
if (itVendor) {
ctx.hint(`IT-Lieferant „${vendor}“: Die IT gibt frei.`);
return ctx.branch('it');
}
return ctx.branch('standard');
},
});

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

  • Eingabe: vendorName Dell Technologies GmbH
  • Ausgang: it
  • Änderungen: Hinweis an der nächsten Aufgabe: „IT-Lieferant „Dell Technologies GmbH“: Die IT gibt frei.“
  • Eingabe: vendorName null
  • Ausgang: der Standard-Nachfolger
  • Änderungen: keine
  • Eingabe: vendorName Bürobedarf Schmidt KG
  • Ausgang: standard
  • Änderungen: keine