2024 Oct 29 5:15 AM
SAP UI Integration Cards provide a seamless way to display data from external sources within your UI5 applications. These versatile cards can be utilized across various platforms, including SAP Build Work Zone, advanced edition, SAP Fiori Launchpad #, and SAP Business Application Studio #, allowing users to gain valuable business insights and interact with data in real-time.
In this blog, I'll walk you through the process step-by-step. We’ll start by defining the card configuration, then set up filters to refine the displayed data. Next, we’ll explore custom data fetching techniques, and finally, I’ll show you how to present the data effectively within the card. Each section will include clear explanations to ensure you can easily follow along and implement these concepts in your own projects.
The manifest.json file is the backbone of the card configuration. Here, we define basic card information such as the title, description, and the type of card.
{
"sap.app": {
"id": "com.example.card.CustomCatalogItemList",
"type": "card",
"title": "Material List Overview",
"subTitle": "Filter and View Material Data",
"description": "A detailed view of catalog items, including item description, manufacturer, delivery time, and category."
}
}
Explanation:
Filters allow users to customize their view by narrowing down the data shown in the card. In this example, we provide filters for ManufacturerName and ItemDescription.
"filters": {
"ManufacturerName": {
"type": "Select",
"label": "Manufacturer Name",
"data": { "extension": { "method": "getDataManufacturerName" } }
},
"ItemDescription": {
"type": "Select",
"label": "Material Name",
"data": { "extension": { "method": "getDataItemDescription" } }
}
}
Explanation:
The actual data fetching from an external API is handled in DataExtension.js. This JavaScript file contains logic to retrieve filtered data from the API and bind it to the card.
DataExtension.prototype.getData = function (ManufacturerName, ItemDescription) {
var filters = [];
if (ManufacturerName && ManufacturerName !== "All Manufacturers") {
filters.push("contains(ManufacturerName,'" + ManufacturerName + "')");
}
if (ItemDescription && ItemDescription !== "All Materials") {
filters.push("contains(ItemDescription,'" + ItemDescription + "')");
}
var filterQuery = filters.length ? "$filter=" + filters.join(" and ") : "";
return this.getCard().request({
"url": "{{destinations.Custom_API_Destination}}/odata/v4/catalog/CatalogItems?" + filterQuery,
"method": "GET"
}).then(function (data) {
return data.value.map(function (item) {
return {
"ItemID": item.ItemID,
"ItemDescription": item.ItemDescription,
"ManufacturerName": item.ManufacturerName,
"DeliveryTime": item.DeliveryTime,
"Category": item.Category
};
});
});
};
Explanation:
In addition to fetching the catalog items, we need to retrieve the unique manufacturers and item descriptions for the filter dropdowns.
Code for Manufacturer Filter:
DataExtension.prototype.getDataManufacturerName = function () {
return this.getCard().request({
"url": "{{destinations.Custom_API_Destination}}/odata/v4/catalog/CatalogItems?$select=ManufacturerName",
"method": "GET"
}).then(function (data) {
var uniqueManufacturers = {};
data.value.forEach(function (item) {
uniqueManufacturers[item.ManufacturerName] = true;
});
return { "ManufacturerNames": Object.keys(uniqueManufacturers).map(name => ({ "ManufacturerName": name })) };
});
};
Explanation:
Code for Item Description Filter:
DataExtension.prototype.getDataItemDescription = function () {
return this.getCard().request({
"url": "{{destinations.Custom_API_Destination}}/odata/v4/catalog/CatalogItems?$select=ItemDescription",
"method": "GET"
}).then(function (data) {
var uniqueDescriptions = {};
data.value.forEach(function (item) {
uniqueDescriptions[item.ItemDescription] = true;
});
return { "ItemDescriptions": Object.keys(uniqueDescriptions).map(description => ({ "ItemDescription": description })) };
});
};
Explanation:
Once the data is fetched from the API, it is displayed in the card’s table. The content section in manifest.json binds this data to the UI elements.
"content": {
"maxItems": 6,
"row": {
"columns": [
{ "title": "Material Name", "value": "{ItemDescription}" },
{ "title": "Manufacturer", "value": "{ManufacturerName}" },
{ "title": "Delivery Time", "value": "{DeliveryTime}{UnitOfMeasure}" },
{ "title": "Category", "value": "{Category}" }
]
}
}
Explanation:
In conclusion, breaking the code into manageable sections highlights how SAP UI Integration Cards provide a flexible and robust method for consuming external API data and presenting it in a user-friendly manner. Utilizing manifest.json for configuration and DataExtension.js for API requests allows for seamless integration of any external data source into your SAP UI5 applications. This approach is particularly useful for consuming OData or any API calls within your UI Integration Cards, enabling you to manipulate data effectively for your specific use case. You can find example code for the same on GitHub:
Github Link: https://github.com/dnp1921/UI-Integation-Card
Linkedin: https://www.linkedin.com/in/vaibhav-singh-44989512a/
2024 Oct 30 5:29 AM
Thanks for the information about integrating the API with UI Integration Card ,very well written and understandable.