In this blog post, We will go through the process of calling CAP actions out of a JavaScript function using the “invokeAction” function of the SAP Fiori elements Edit flow API.
In CAP, actions can be bound to a specific entity or unbound and just be a part of the service. Bound actions can only be executed, when at least one entity is selected. Unbound actions can be executed anytime.
It is possible to invoke CAP actions out of a JavaScript function using the “invokeAction” function of the SAP Fiori elements Edit flow API.
Note: The purpose of this blog is mainly to demonstrate how to create a CAP action and call it from within the Fiori elements application.
I have taken the reference from
A controller extension offering hooks into the edit flow of the application
In this article will discuss
1) An example of a simple CAP action would be the addition of two numbers.
2) How to use the custom action button to invoke the CAP action from the Fiori elements application.
Lets get started.
1) An example of a simple CAP action would be the addition of two numbers.
- Create the simple CAP action in the service definition of the cap application as shown below.
- The extension logic that will be written when the cap action is called is now displayed below.
- I have created a custom action using the SAP FPM Fiori elements application, as indicated below.
-
invoke CAP actions out of a JavaScript function using the “invokeAction” function of the SAP Fiori elements Edit flow API as shown below.
sActionName: The name of the action to be called.
mInParameters:
- contexts: For a bound action, a context or an array with contexts for which the action is to be called must be provided.
- label: A human-readable label for the action. This is needed in case the action has a parameter and a parameter dialog is shown to the user. The label will be used for the title of the dialog and for the confirmation button.
- model: For an unbound action, an instance of an OData V4 model must be provided.
- parameterValues: A map of action parameter names and provided values.
- skipParameterDialog: Skips the action parameter dialog if values are provided for all of them in parameterValues.
- Now that the action can be triggered via the UI, let’s observe the outcome.
Conclusion
After going through this post, you should be able to call the bound and unbound CAP actions from Fiori elements using Edit Flow. I hope this guide has been helpful and if you have any questions or comments, please feel free to leave them below.
- Please follow https://community.sap.com/topics/ui5 for SAPUI5 Topic related updates.
- Post questions and answers on SAPUI5 here.
- Read other posts on SAPUI5 here.
Please follow me for the future updates.