how to combine price and currency fields in fiori elements header using annotations.cds
- User
how to combine price and currency fields in fiori elements header using annotations.cds
- Assistant
how to combine price and currency fields in fiori elements header using annotations.cds
In SAP Fiori Elements, which leverages SAPUI5 and OData for front-end UI rendering using metadata annotations, combining fields such as price and currency into a single field in the UI can be achieved through annotations in your CDS (Core Data Services) views. This allows the Fiori app to display data in a more user-friendly format without altering the underlying backend data structure.
To achieve this, you typically need to modify the CDS view that serves as the data source for your Fiori Elements application. Here's a general guide on how you might approach this:
First, create or extend a CDS view to include a calculated field that combines the price and currency into a single string. You will also need to ensure that the currency code is available in the view.
@AbapCatalog.sqlViewName: 'ZMY_VIEW'
define view ZMyView as select from underlying_table {
key some_key_field,
price,
currency_code,
concat(price, ' ', currency_code) as price_with_currency
}
Ensure that the combined field (price_with_currency) is exposed in your OData service that the Fiori Elements app will consume. This might involve adjustments in the CDS view annotations specific to OData exposure:
@OData.publish: true
define view ZMyView as select from underlying_table {
key some_key_field,
@UI.lineItem: [{ position: 10 }]
@UI.identification: [{ position: 10 }]
concat(price, ' ', currency_code) as price_with_currency
// include other fields necessary for your application
}
You might need additional annotations to control how this combined field is displayed in the Fiori Elements app. For example, you can control its label, position, or formatting within the UI:
@UI: {
lineItem: [{ position: 20, label: 'Price with Currency' }],
identification: [{ position: 20, label: 'Price with Currency' }]
}
concat(price, ' ', currency_code) as price_with_currency
After you've made these changes, deploy your CDS view and the associated OData service, then check your Fiori app to see if the combined field displays as expected.
Make sure that your Fiori Elements application is set up to utilize this OData service, specifically ensuring that the entity set and entity type in the app's manifest.json file are pointing correctly to the ones provided by your CDS view.
By adhering to this guide, you can effectively combine the price and currency fields in the header or other parts of your Fiori Elements application through the use of CDS annotations and ensure a clean and efficient presentation of the data. If you encounter any specifics, such as requirements for different visual representations or handling multiple currency formats, you might need to adjust the approach accordingly.
Not yet included in a published release.