You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/providing-services.md
+26-23Lines changed: 26 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1264,7 +1264,7 @@ For CAP Java, support for flows is provided by the feature [cds-feature-flow](ht
1264
1264
The following example, taken from [@capire/xtravels](https://github.com/capire/xtravels), shows the simplest way to model a flow.
1265
1265
The annotations in the service model are sufficient to define and use the flow.
1266
1266
1267
-

1267
+

1268
1268
1269
1269
The following is an extract of the relevant parts of the domain model:
1270
1270
@@ -1319,7 +1319,7 @@ For more complex scenarios, you can add custom handlers as explained later.
1319
1319
1320
1320
Flows consist of a _status element_ and a set of _flow actions_ that define transitions between states.
1321
1321
1322
-
#### `@flow.status`
1322
+
#### Declare Flow Using `@flow.status`
1323
1323
1324
1324
To model a flow, one of the entity fields needs to be annotated with `@flow.status`.
1325
1325
This field must be one of the following:
@@ -1336,34 +1336,37 @@ As no initial state can be provided on `CREATE`, there should be a default value
1336
1336
1337
1337
When you annotate `@flow.status: <element name>` at the entity level (as in the example above), the annotation is propagated to the respective element, which is also automatically annotated with `@readonly`.
1338
1338
1339
-
**Notes:**
1340
-
- This annotation is mandatory
1341
-
- The annotated element must be either an enum or an association to a code list
1342
-
- Only one status element per entity is supported
1343
-
- Draft-enabled entities are supported, however flows are only applied to the active version
1344
-
-`null` is **not** a valid state—model your empty state explicitly
1339
+
**About the `@flow.status` annotation:**
1340
+
- This annotation is **mandatory**.
1341
+
- The annotated element must be either an enum or an association to a code list.
1342
+
- Only one status element per entity is supported.
1343
+
- Draft-enabled entities are supported, however flows are only applied to the active version.
1344
+
-`null` is **not** a valid state—model your empty state explicitly.
1345
1345
1346
1346
::: warning Only simple projections are supported
1347
1347
The entity must be _writable_, and renaming the status element is currently not supported.
1348
1348
:::
1349
1349
1350
1350
After declaring `@flow.status`, use the following annotations on bound actions to model transitions:
1351
1351
1352
-
#### `@from`
1352
+
#### Model Transitions Using `@from` and `to`
1353
1353
1354
-
- Defines valid entry states for the action
1355
-
- Validates whether the entity is in a valid entry state before executing the action (the current state of the entity must be included in the states defined here)
1356
-
- Can be a single value or an array of values (each element must be a value from the status enum)
1357
-
- UI annotations to allow/disallow buttons and to refresh the page are automatically generated for UI5
1358
-
- Annotation generation can be deactivated via <Config>cds.features.annotate_for_flows: false</Config>
1354
+
Both annotations are optional, but at least one is required to mark an action as a flow action. Use either one or both depending on your needs. When you use both, no custom handlers are needed—generic handlers are registered automatically.
1359
1355
1360
-
#### `@to`
1356
+
**`@from`**
1361
1357
1362
-
- Defines the desired target state of the entity after executing the action
1363
-
- Changes the state of the entity to the value defined in this annotation after executing the action
1364
-
- Must be a single value from the status enum
1358
+
- Defines valid entry states for the action.
1359
+
- Validates whether the entity is in a valid entry state before executing the action (the current state of the entity must be included in the states defined here).
1360
+
- Can be a single value or an array of values (each element must be a value from the status enum).
1361
+
- UI annotations to allow/disallow buttons and to refresh the page are automatically generated for UI5.
1362
+
- Can be deactivated via <Config>cds.features.annotate_for_flows: false</Config>.
1363
+
1364
+
**`@to`**
1365
+
1366
+
- Defines the desired target state of the entity after executing the action.
1367
+
- Changes the state of the entity to the value defined in this annotation after executing the action.
1368
+
- Must be a single value from the status enum.
1365
1369
1366
-
Both annotations are optional, but at least one is required to mark an action as a flow action. Use either one or both depending on your needs. When you use both, no custom handlers are needed—generic handlers are registered automatically.
1367
1370
1368
1371
1369
1372
### Generic Handlers
@@ -1372,7 +1375,7 @@ Generic handlers are registered automatically, so no custom implementations are
1372
1375
1373
1376
#### `before`
1374
1377
1375
-
Based on the `@from` annotation, a handler validates that the entity is in a valid entry state—the current state must match one of the states specified in `@from`.
1378
+
Based on the `@from` annotation, a handler validates that the entity is in a valid entry state - the current state must match one of the states specified in `@from`.
1376
1379
If validation fails, the request returns a `409 Conflict` HTTP status code with an appropriate error message.
1377
1380
1378
1381
#### `on`
@@ -1387,7 +1390,7 @@ For example, if the current state is `Open` and the target state is `Accepted`,
1387
1390
This ensures consistent state transitions without custom logic.
1388
1391
1389
1392
::: tip Generic handlers are not executed for draft entities
1390
-
For example, calling `acceptTravel()` on a `Travels` entity that is currently being _edited_, i.e. is in _inactive_ state, has no effect.
1393
+
For example, if you call `acceptTravel()` on a `Travels` entity that is currently being edited (in _inactive_ state), the call has no effect.
1391
1394
:::
1392
1395
1393
1396
@@ -1397,7 +1400,7 @@ You can use the target state `$flow.previous` to restore the previous state in a
1397
1400
The following example introduces a `Blocked` state with two possible previous states (`Open` and `InReview`) and an action `unblockTravel` that restores the previous state.
1398
1401
For instance, if `Blocked` was transitioned to from `Open`, calling `unblockTravel` transitions back to `Open`. The same applies for `InReview`.
1399
1402
1400
-

1403
+

1401
1404
1402
1405
```cds [srv/travel-service.cds]
1403
1406
// srv/travel-service.cds
@@ -1448,7 +1451,7 @@ The `transitions_` composition automatically appended to the base entity is also
1448
1451
1449
1452
Flow annotations work well for basic flows. For more complex scenarios, implement custom event handlers.
1450
1453
1451
-
**Common use cases for custom handlers:**
1454
+
Common use cases for custom handlers:
1452
1455
-**Additional validation:** Implement a custom `before` handler when entry state validation depends on extra conditions
1453
1456
-**Non-void return types:** Implement a custom `on` handler when the action returns data
1454
1457
-**Conditional target states:** Implement a custom `on` or `after` handler (without `@to` annotation) when multiple target states depend on conditions
0 commit comments