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
+12-11Lines changed: 12 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -941,7 +941,7 @@ The `@assert.target` check constraint relies on database locks to ensure accurat
941
941
942
942
### `@assert` <Beta/>
943
943
944
-
Annotate an _element_ with `@assert` to define the CXL expressions that are validated _after_ the data has been written to the database but _before_ it is committed. If the validation fails, the expression will return a `String` that indicates an error to the runtime. If the validation passes the expression return`null`
944
+
Annotate an element with `@assert` to define CXL expressions that are validated _after_ the data has been written to the database but _before_ it is committed it. If validation fails, the expression returns a `String` that indicates an error to the runtime. If validation passes, the expression returns`null`.
945
945
946
946
```cds
947
947
entity OrderItems : cuid {
@@ -953,7 +953,7 @@ entity OrderItems : cuid {
953
953
}
954
954
```
955
955
956
-
Alternatively, the same condition can be simplified by using the [ternary conditional operator](../releases/archive/2023/march23#ternary-conditional-operator):
956
+
You can simplify the same condition by using the [ternary conditional operator](../releases/archive/2023/march23#ternary-conditional-operator):
957
957
958
958
```cds
959
959
entity OrderItems : cuid {
@@ -965,23 +965,23 @@ entity OrderItems : cuid {
965
965
966
966
#### Error Messages and Message Targets
967
967
968
-
If a validation fails, the transaction is rolled back with an exception. If you use [Fiori draft state messages](../advanced/fiori#validating-drafts) the error is persisted. The error targets the annotated element, which is then highlighted on the Fiori UI.
968
+
In general, if validation fails, the transaction is rolled back with an exception. But, if you use [Fiori draft state messages](../advanced/fiori#validating-drafts), the error is persisted. The error targets the annotated element, which is then highlighted on the Fiori UI.
969
969
970
970
::: info Error Messages
971
-
The error message returned by the CXL expression inside the annotation can be either a static message or a message key to support i18n. If a message key is used, the message is looked up in the message bundle of the service.
972
-
[Learn more about localized messages](./i18n){.learn-more}
971
+
The CXL expression in the annotation can return either a static error message or a message key to support i18n. If you use a message key, the message is looked up in the message bundle of the service.
972
+
[Learn more about localized messages.](./i18n){.learn-more}
973
973
:::
974
974
975
975
976
976
#### Complex Asserts
977
977
978
978
::: warning Use complex asserts on service layer
979
-
Like other annotations, `@assert` is propagated to projections. If you annotate an element with `@assert` and the condition uses other elements - from the same or an associated entity - you must ensure that these elements are available in all projections to which the annotated element is propagated. Otherwise the CDS model won't compile.
979
+
Like other annotations, `@assert` is propagated to projections. If you annotate an element with `@assert` and the condition uses other elements from the same or an associated entity, you must ensure that these elements are available in all projections to which the annotated element is propagated. Otherwise the CDS model won't compile.
980
980
981
981
It is therefore recommended to use complex asserts on the highest projection, that is on the service layer.
982
982
:::
983
983
984
-
For the examples given in this section, consider the following CDS _domain_ and _service_ model:
984
+
For the examples given in this section, consider the following _domain_ and _service_ model:
985
985
986
986
```cds
987
987
context db {
@@ -1009,14 +1009,15 @@ service OrderService {
1009
1009
}
1010
1010
```
1011
1011
1012
-
An `@assert` annotation may use other elements from the same entity. This annotation checks that the delivery date of an order is after the order date:
1012
+
An `@assert` annotation can use other elements from the same entity. This annotation checks that the delivery date of an order is after the order date:
In an `@assert` condition you can also refer to elements of associated entities. The following example ensures that the `quantity` of the ordered book is validated against the actual `stock`. If the stock level is insufficient, a static error message is returned:
1019
+
1020
+
In an `@assert` condition, you can also refer to elements of associated entities. The following example validates the `quantity` of the ordered book against the actual `stock`. If the stock level is insufficient, a static error message is returned:
1020
1021
1021
1022
```cds
1022
1023
annotate OrderService.OrderItems with {
@@ -1052,11 +1053,11 @@ annotate OrderService.OrderItems with {
1052
1053
1053
1054
#### Background
1054
1055
1055
-
Expressions are evaluated *after*the request has been applied to the underlying datastore. Affected are the entities of the request's payload. The runtime executes check-statements with the provided expressions and the primary key values for the given entities.
1056
+
The system evaluates expressions after it applies the request to the underlying datastore. This affects the entities in the request's payload. The runtime executes checkstatements with the provided expressions and the primary key values for the given entities.
1056
1057
1057
1058
::: warning Limitations
1058
1059
- All primary key fields need to be contained in the CQN statement for validations to be enforced (including deep insert and deep update).
1059
-
- Only elements with simple types (like,`String`, `Integer`, `Boolean`) can be annotated with `@assert`. Elements typed with structured or arrayed types are not supported.
1060
+
- Only elements with simple types (like `String`, `Integer`, `Boolean`) can be annotated with `@assert`. Elements typed with structured or arrayed types are not supported.
0 commit comments