Skip to content

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

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

  • Input: vendorName Dell Technologies GmbH
  • Exit: it
  • Changes: hint on the next task: “IT-Lieferant „Dell Technologies GmbH“: Die IT gibt frei.”
  • Input: vendorName null
  • Exit: the default next step
  • Changes: none
  • Input: vendorName Bürobedarf Schmidt KG
  • Exit: standard
  • Changes: none