Route by vendor
The IT approves invoices of IT vendors such as Telekom or Dell, the cost center’s responsible person all others. The list of IT vendors is in the script, and the IT’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-vendorname: Nach Lieferant weiterleitentemplate: customtrigger: documentType: incoming-invoicefields: []start: routesteps: - 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: rejectedThe script route.ts
Section titled “The script route.ts”Hook: onDocumentArrived · Inputs: vendorName · Return values: 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'); },});What it does
Section titled “What it does”A test runs each of these cases in the sandbox and compares the result.
An IT vendor
Section titled “An IT vendor”- Input:
vendorNameDell Technologies GmbH - Exit:
it - Changes: hint on the next task: “IT-Lieferant „Dell Technologies GmbH“: Die IT gibt frei.”
An invoice without a vendor
Section titled “An invoice without a vendor”- Input:
vendorNamenull - Exit: the default next step
- Changes: none
Another vendor
Section titled “Another vendor”- Input:
vendorNameBürobedarf Schmidt KG - Exit:
standard - Changes: none