Set up ANS, use @cap-js/notifications, configure condition-based routing, and integrate with Fiori Notification Hub.
console.error doesn't page the on-call engineer at 3am. ANS connects your CAP app to real notification channels — email, Slack, PagerDuty via webhooks — with filtering and routing so the right people get the right alerts.
CAP App → ANS → Routing Engine (conditions) → Delivery Channels
├── Email (SMTP)
├── Slack webhook
├── Microsoft Teams
├── SAP Fiori Launchpad notification
└── Custom webhook
# mta.yaml
resources:
- name: alert-notification
type: org.cloudfoundry.managed-service
parameters:
service: alert-notification
service-plan: standard
modules:
- name: bookshop-srv
requires:
- name: alert-notification
// .cdsrc.json
{
"requires": {
"notifications": {
"[production]": {
"kind": "alert-notification",
"vcap": { "label": "alert-notification" }
},
"[development]": {
"kind": "@cap-js/notifications",
"impl": "@cap-js/notifications/lib/console-logger" // logs to console in dev
}
}
}
}
npm install @cap-js/notifications
const notif = await cds.connect.to('notifications')
this.on('submitOrder', async (req) => {
const { orderId } = req.data
const order = await SELECT.one.from('Orders').where({ ID: orderId })
// Business notification to the buyer
await notif.notify({
NotificationTypeKey: 'OrderConfirmed',
NotificationTypeVersion: '1',
Priority: 'MEDIUM',
Properties: [
{ Key: 'orderId', Value: order.ID },
{ Key: 'orderTotal', Value: String(order.total) }
],
Recipients: [{ RecipientId: order.buyer_email }]
})
return order
})
// Global error handler — alert on 5xx errors
this.on('error', async (err, req) => {
if (err.status >= 500) {
await notif.notify({
NotificationTypeKey: 'SystemError',
Priority: 'HIGH',
Properties: [
{ Key: 'errorMessage', Value: err.message },
{ Key: 'operation', Value: `${req.event} ${req.target?.name}` },
{ Key: 'user', Value: req.user?.id || 'anonymous' }
],
Recipients: [{ RecipientId: 'ops-team@company.com' }]
})
}
})
In ANS Cockpit (BTP → Instances → alert-notification → Manage):
1. Notification Types → Create:
- Key: OrderConfirmed
- Version: 1
- Template for email subject: "Order {{orderId}} confirmed"
- Template for email body: "Your order total: {{orderTotal}}"
EMAILNotificationTypeKey = 'OrderConfirmed'Conditions in ANS:
Priority == 'HIGH' → PagerDuty webhook
NotificationTypeKey == 'SystemError' → Slack #ops-alerts
NotificationTypeKey == 'OrderConfirmed' → Email to buyer
Region == 'EMEA' → EMEA support team
// Fiori notifications appear in the Fiori Shell notification bell
await notif.notify({
NotificationTypeKey: 'ApprovalRequired',
Priority: 'HIGH',
Properties: [
{ Key: 'documentId', Value: req.data.ID },
{ Key: 'amount', Value: String(req.data.amount) }
],
Recipients: [{ RecipientId: req.data.approver_email }],
// NavigationTargetObject: target Fiori app to open on click
NavigationTargetObject: 'PurchaseOrder',
NavigationTargetAction: 'approve',
NavigationTargetParams: [{ Key: 'documentId', Value: req.data.ID }]
})
@cap-js/notifications and configure it for development (console logger)@cap-js/notifications in dev mode logs to console — no ANS service needed locally