I have a CAP Service that provides a PDF file that I needed to display in a Fiori Elements frontend using the sap.m.PDFViewer. The viewer should be placed in a section on the object page after navigating from the ListReport main page.
My CAP Service has the following annotations to provide the PDF.
In the documentation they always use a star in string literals like this o => o.`*` to select all fields, but when running this it always failed. However, after some tests I found that this format works with brackets o => o.('*')
/*
* Handover query to some external SF OData Service to fecth the requested data
*/
srv.on("READ", Whatever, async req => {
const sf_api_def = cds.env.requires['sfsf'] //defined in package.json
sf_api_def.credentials.destination = "myDestinationName" //set your Destination name, could come from a customizing table
const sfsfSrv = await cds.connect.to(sf_api_def)
return await sfsfSrv.run(req.query)
})
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
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