Skip to content

Commit 2061149

Browse files
committed
Moved and updated the Script Task API
1 parent 18682e7 commit 2061149

3 files changed

Lines changed: 39 additions & 56 deletions

File tree

content/developer/_meta.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { MetaRecord } from 'nextra';
22

33
const meta: MetaRecord = {
4+
'script-task-api': 'Script Task API',
45
'bpmn': 'BPMN Serialization',
56
'ms-api': {
67
title: 'MS API',

content/developer/bpmn/_meta.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
import type { MetaRecord } from "nextra";
1+
import type { MetaRecord } from 'nextra';
22

33
const meta: MetaRecord = {
4-
"bpmn-supported": "Supported Elements",
5-
"bpmn-general-serialization": "General Serialization",
6-
"bpmn-data-types": "Process Variables and Types",
7-
"bpmn-script-task": "Script Task & API",
8-
"bpmn-user-tasks": "User Tasks",
9-
"bpmn-subprocesses": "Subprocesses",
10-
"bpmn-gateways": "Gateways",
11-
"bpmn-error-escalation": "Error & Escalation Events",
12-
"bpmn-timer": "Timer Events",
13-
"bpmn-constraints": "Process and Task Constraints",
14-
"bpmn-capabilities": { display: "hidden" },
4+
'bpmn-supported': 'Supported Elements',
5+
'bpmn-general-serialization': 'General Serialization',
6+
'bpmn-data-types': 'Process Variables and Types',
7+
'bpmn-user-tasks': 'User Tasks',
8+
'bpmn-subprocesses': 'Subprocesses',
9+
'bpmn-gateways': 'Gateways',
10+
'bpmn-error-escalation': 'Error & Escalation Events',
11+
'bpmn-timer': 'Timer Events',
12+
'bpmn-constraints': 'Process and Task Constraints',
13+
'bpmn-capabilities': { display: 'hidden' },
1514
};
1615

1716
export default meta;

content/developer/bpmn/bpmn-script-task.mdx renamed to content/developer/script-task-api.mdx

Lines changed: 27 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
BPMN Script Tasks can be used in process diagrams for a PROCEED engine.
1+
## BPMN Script Tasks and their API
22

3-
## General Aspects
3+
An executable BPMN diagram can contain Script Tasks.
4+
In PROCEED, you can use pure JavaScript to write functionalities for the process.
5+
Therewith, you also have access to APIs for accessing process variables or to trigger network requests.
46

5-
You can use pure JavaScript to write functionalities for the process. Thereby,
6-
you also have access to a bunch of APIs for accessing process variables or
7-
trigger network requests (see [API](#api)).
8-
9-
At the end of the script there can be a `return`, ending the script. The
10-
`return` may return an object with properties/value pairs which will update the
11-
process variable. A Script Task can also end by a semantic error, which will be
7+
At the end of the script there can be a `return`, ending the script.
8+
The `return` may return an object with properties/value pairs which will update process variables.
9+
A Script Task can also end by a semantic error, which will be
1210
caught by an attached boundary _Error_ or _Escalation_ event. This is done by
1311
throwing an `BpmnError` or an `BpmnEscalation`.
1412

1513
If an error is thrown but not caught within the BPMN process, or if the script
16-
itself has an error (e.g. syntax error), the token will end its execution..
14+
itself has an error (e.g. syntax error), the token will end its execution.
1715
(This only stops the running token, not the whole process.)
1816

1917
The code of a script task is usually executed within a sandboxed JavaScript
@@ -37,31 +35,25 @@ the customer is informed that the order got canceled.
3735

3836
#### Example Script Code
3937

40-
```xml
41-
<bpmn2:scriptTask id="Task_1pdn5o1" scriptFormat="application/javascript">
42-
<bpmn2:script>
43-
<![CDATA[
44-
const amount = variable.get('amount'); // amount of the ordered products
45-
const cost = variable.get('cost'); // cost of the ordered products
46-
47-
if (cost < 50) {
48-
// update the costs
49-
try {
50-
// add shipping costs to total cost
51-
variable.set('cost', cost+5);
52-
} catch(err) {
53-
log.info('Error occured while processing order: ' + err);
54-
throw new BpmnError('A severe error occured while processing');
55-
}
56-
}
57-
58-
if (amount > 100) {
59-
// execute alternative flow to the attached escalation boundary-event
60-
throw new BpmnEscalation('late shipment', 'The order is too much');
61-
}
62-
]]>
63-
</bpmn2:script>
64-
</bpmn2:scriptTask>
38+
```js
39+
const amount = variable.get('amount'); // amount of the ordered products
40+
const cost = variable.get('cost'); // cost of the ordered products
41+
42+
if (cost < 50) {
43+
// update the costs
44+
try {
45+
// add shipping costs to total cost
46+
variable.set('cost', cost + 5);
47+
} catch (err) {
48+
log.info('Error occured while processing order: ' + err);
49+
throw new BpmnError('A severe error occured while processing');
50+
}
51+
}
52+
53+
if (amount > 100) {
54+
// execute alternative flow to the attached escalation boundary-event
55+
throw new BpmnEscalation('late shipment', 'The order is too much');
56+
}
6557
```
6658

6759
## API
@@ -160,15 +152,6 @@ There are special functionalities for accessing system resources. They can be
160152
accessed via _services_ by calling `getService( 'service' )`. Services are
161153
provided by the PROCEED Engine. The following services are currently offered:
162154

163-
#### `getService('capabilities')`
164-
165-
| API | Access to the systems capabilities |
166-
| ----------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
167-
| `.startCapability( „<Capability-Name>“, [<{ Parameter-Object }>], [<clb function>] )`<br /> Return value: `if clb then null else Promise` | Call the capability Function and give a list of parameters. |
168-
| E.g.<br />`await startCapability( „PhotographAction“, { height: 80, width: 80 } )` | |
169-
| E.g. Variant 1:<br />`await startCapability( „PhotographAction“, { height: { value: 80, unit: “px” } )` | Needed for the Management System to determine the correct Capability Description if there are multiple Description of the same Capability kind (e.g. two times "PhotoAction") with different Parameter units, e.g. "cm" and "pt" |
170-
| E.g. Variant 2:<br />`await startCapability( „https://schema.org/PhotographAction“, { “https://schema.org/height”: 80 } )` | Only needed for the Management System to determine the correct Capability Description if there are multiple descriptions of the same capability kind or its parameter (e.g. "height" from "schema.org/height" and from "vocab.org/height") |
171-
172155
#### `getService('network')`
173156

174157
Inside of a Script Task it is possible to send HTTP requests to a given URL. The

0 commit comments

Comments
 (0)