Example 1: Use OData Actions in an Application

You can execute OData (V4) actions exposed by a connected on-premise SAP S/4HANA system within an analytic application.

Prerequisites

You have created an analytic application and have added an OData service to your application.

Context

In this example you see the following elements for ODataService_1:

  • The system: FUB

  • The end-point URL for the OData service

  • As metadata, the OData version and two actions, Flight/Book and CancelMyFlights

Procedure

  1. Insert a Button widget and change the text of the button to Cancel Flight in the Properties of the Styling panel.
  2. Start the script editor by clicking in the quick actions menu of the widget.

    You will be creating a script to trigger execution of the OData action in the source system.

    The script editor opens.

  3. Type in the name of the OData service you have added and specified.

    The script editor assists you with code completion and value help wherever possible when you click CTRL + Space . In the script editor, do the following:

    1. Type in the name of the OData Service: ODataService_1, followed by .
    2. Press CTRL + Space , then select the function executeAction().
    3. Place the mouse cursor between the brackets ( () ) and press CTRL + Space , then select action CancelMyFlights from the value help of executeAction(), followed by , and {}. Select Action CancelMyFlights from value help of executeAction() by placing the cursor between the brackets ( () )and CTRL + Space , followed by, and {}.
    4. Place the mouse cursor between the brackets ({}), then press CTRL + Space to select the parameter DateFrom from value help,, followed by : .
    5. Type in the date 2019-01-01, followed by ,.
    6. Press CTRL + Space and select DateTo from value help, folllowed by :.
    7. Type in the date 2019-12-31 and finish with ;.

    You have created a script to execute an OData action. This action has a simple syntax with two parameters and looks like this:

    ODataService_1.executeAction("CancelMyFlights", {DateFrom: "2019-01-01", DateTo: "2019-12-31"}); 
  4. Insert another button, rename it to Book Flight in the Styling panel, and open the script editor.

    The BookFlight Action is a bound action which is more complex than the first one.

  5. Type in the following script in the script editor by using code completion and value help:
    ODataService_1.executeAction("Flight/Book", {Flight:{Airline:"UA",Flightconnection:"0941", Flightdate: "2019-01-05"},NumberOfSeats: 1}); 

Results

You finished a simple OData action and a second one that is more complex. Now you can run your application and book and cancel flights for the selected values.

You can enhance your application and start using other script methods to fill the parameter values dynamically with local or global variables.

Finally, you can make the response from the backend system visible in the application by writing the response as a message in a text field.

To find out how to do this, see Example 2: Using OData Actions in an Application