Homelab, Linux, JS & ABAP (~˘▾˘)~
 

[CAP] Use Destinations from Subscriber Account

While working on this topic, there are currently two chapters in the CAP docs regarding this topic:

And some SCN posts: herehere and here

But all this didn’t help me to complete the task. Got the solution which finally worked for me from this SAP Sample Susaas (two snippets: here and here).

server.js

01
02
03
04
05
06
07
08
09
10
11
12
13
14
const cds = require("@sap/cds")
 
cds.on('served', async () => {
    const { 'cds.xt.SaasProvisioningService': provisioning } = cds.services
    // Add provisioning logic only if multitenancy is there..
    if (provisioning) {
        let tenantProvisioning = require('./provisioning')
        provisioning.prepend(tenantProvisioning)
    } else {
        console.log(">>> There is no service, therefore does not serve multitenancy!")
    }
})
 
module.exports = cds.server

provisioning.js

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
const xsenv = require('@sap/xsenv')
xsenv.loadEnv()
 
module.exports = (service) => {
 
    service.on('dependencies', async (req, next) => {
        let dependencies = await next()
        const services = xsenv.getServices({
            registry: { tag: 'SaaS' },
            destination: { tag: 'destination' }
        })
        dependencies.push({ xsappname: services.destination.xsappname }) //adds the subscriber destination as dependency
        console.log(">>> SaaS Dependencies:", JSON.stringify(dependencies))
        return dependencies
    })
 
}

It injects the destination dependency by manually reading it using xsenv package and returning it in a dependencies callback handler.