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.
I have provided a sample project. You will have to create your own destination and set the proper destination in the data resource.
I will use the example OData service described here: https://www.odata.org/blog/trippin-new-odata-v4-sample-service/
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).
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.
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.
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.
For the UI, I created 4 page parameters as follows:
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:
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.
For the Create record, I bound the 2 page parameters to the 2 input parameters I added to the data resource.
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
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.
Enjoy 😺
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.