SAP Builders Blog Posts
Learn from peers about their low-code journey and write your own blog posts to share your thoughts and experiences as you become an SAP Builder.
cancel
Showing results for 
Search instead for 
Did you mean: 
Dan_Wroblewski
Developer Advocate
Developer Advocate

THE BAD NEWS: SAP Build Apps currently does not automate calling OData functions or actions – you cannot define an OData resource and automatically see all the functions and actions.

THE GOOD NEWS: There's an easy workaround.

dan_wroblewski_0-1703436060934.png

I have provided a sample project. You will have to create your own destination and set the proper destination in the data resource.

dan_wroblewski_0-1703436060934.png

I will use the example OData service described here: https://www.odata.org/blog/trippin-new-odata-v4-sample-service/ 

dan_wroblewski_1-1703436512966.png

There is a function called GetNearestAirport that takes 2 URL parameters (latitude and longitude) and gives the nearest airport.

I created a destination to the service (not to the function).

dan_wroblewski_2-1703436814285.png

Data Resource

After enabling BTP authentication, I created a data resource of type "SAP BTP destination REST API integration", selected my destination, and added the 2 URL parameters as part of the schema.

dan_wroblewski_3-1703436993314.png

Then I defined the "Create" operation, and set the path to the following formula:

 

 

"/GetNearestAirport(lat=" + query.record.lat + ",lon=" + query.record.lon + ")"

 

 

I also changed the HTTP method to GET.

dan_wroblewski_4-1703437309716.png

I did not use the "Retrieve" operation because it assumed only id as an input parameter, and when you go to the Test tab you will only see id and not the 2 parameters defined in the schema.

If you test it and enter the test values, you will get the data from the backend.

dan_wroblewski_13-1703438467388.png

UI

For the UI, I created 4 page parameters as follows:

  • lat: The latitude URL parameter
  • lon: The longitude URL parameter
  • NameAirport: The name of the closest airport (to come from the response)
  • AirportCode: The code of the closest airport (to come from the response)

dan_wroblewski_6-1703437491838.png

I then created a UI with 2 input fields for the user to enter the latitude and longitude, and 2 text fields to display the airport name and code. The bindings are shown in the screenshot below:

dan_wroblewski_7-1703437705635.png

Logic

For the button logic, I added a Create record flow function, whose success output go to 2 Set page variable flow functions to set the airport name and code.  I added an Alert in case of error.

dan_wroblewski_8-1703437960688.png

For the Create record, I bound the 2 page parameters to the 2 input parameters I added to the data resource.

dan_wroblewski_9-1703438035036.png

For the Set page variable for the airport name, I used a formula because the schema of the response could not be defined so I could not bind directly to a data variable or the output.

The formula was:

 

 

outputs["Create record"].response.Name

 

 

dan_wroblewski_10-1703438161408.png

Note the warning, since SAP Build Apps has no knowledge of the Name field in the output. I made a similar binding to the other Set page variable, except to the IataCode field.

When I run it, I enter the latitude and longitude, and I get the airport from the response of the OData function.

dan_wroblewski_11-1703438327498.png

Enjoy 😺

 

3 Comments