In SAP Fiori elements, you can use generic actions such as Delete and Create. If your app needs actions beyond this scope, you can create your own application-specific actions.
App-specific actions can be either annotation-based actions or custom actions.
Annotation-Based Actions
Annotation-based actions are created using corresponding annotations. They can be used in the following cases:
- User confirmation is required, for example for critical actions. A popover dialog opens, and the user has to confirm the action. For more information, see Adding Confirmation Popovers for Actions.
- Additional user input is required. Some values may already be filled in.
- The action triggers a back-end call through an OData service, such as Approve.
- The action triggers navigation, for example to a different app. For more information, see Configuring Navigation.
Custom Actions
Custom actions can be created if the action you need cannot be covered by annotation-based actions. They are created using extension points which need to be registered in the manifest.json file. For more information, see Adding Custom Actions Using Extension Points.
Visibility of Annotation-Based Actions
You can change the visibility of annotation-based actions with the @Core.OperationAvailable annotation.
The annotation can either have a static value (Boolean true or false) or a dynamic value (a path pointing to a property). If the value is static and set to true, the action will always be available, regardless of which item is selected. If the value is dynamic, the action can be enabled or disabled dynamically, depending on a certain condition.
Have a look at the following CAP CDS annotation:
12345actions {
deductDiscount @(
Core.OperationAvailable : { $edmJson: { $Eq: [{ $Path: 'in/TravelStatus_code'}, 'O']}}
);
}
In this example, the action deductDiscount will only be available for items with the TravelStatus'O' (open). The value for the annotation Core.OperationAvailable is a dynamic expression enclosed in { $edmJson: { … }}.
For more information about dynamic expressions in OData Version 4, see OData Common Schema Definition Language (CSDL) JSON Representation Version 4.01 (oasis-open.org).
The CDS compiler translates the expression into the corresponding XML code. The annotation above is translated to the following OData representation:
12345678<Annotations Target="TravelService.deductDiscount(TravelService.Travel)">
<Annotation Term="Core.OperationAvailable">
<Eq>
<Path>in/TravelStatus_code</Path>
<String>O</String>
</Eq>
</Annotation>
</Annotations>
For more information about CAP CDS and dynamic expressions, see: Dynamic Expressions.