Showing results for 
Search instead for 
Did you mean: 

CAP: Select inside Action

Active Contributor
0 Kudos


I'm struggling to implement an Action inside CAP.

What I want to do is simple SELECT, but it throws me an error...

Service definition

using { demo.callcenter as call } from '../db/schema';

service CallCenterService {
    entity Inquiries as select from call.Inquiries
    actions {
        @sap.applicable.path: 'startEnabled'
        action start();

Service implementation

const cds = require('@sap/cds')

module.exports = async function () {
    const { Inquiries } = cds.entities

    this.on ('start', async (req)=> {
        console.log('data: ' +
        const id = req.params[0]

        //Get createdAt
        const createdAt = await SELECT.from(Inquiries).columns(['createdAt']).where({ID:id})

        //Calculate hoursBeforeStart
        const startedAt =
        const difference = startedAt - new Date(createdAt).getTime()
        const hoursBefoerStart =  Math.floor(difference/1000/60/60)        

        const n = await UPDATE(Inquiries).set({ 
            hoursBefoerStart: hoursBefoerStart
        }).where ({ID:id}).and({status_code:'1'})
        n > 0 || req.error (404) 

The error is occurring at below statement.

const createdAt = await SELECT.from(Inquiries).columns(['createdAt']).where({ID:id})

Can anybody point out what's wrong with this statement?



0 Kudos

Hi Mio,

There is not enough information provided to find the reason behind your issue. Could you please provide us a link to your project or a minimal working example which will help us to reproduce the problem?

Best regards,


Active Contributor
0 Kudos

Hi Olena,

Thank you for your attention.

I have uploaded my project to below git repository.

You can reproduce the issue by executing the POST request in srv/test.http file.

Best regards,


Active Contributor
0 Kudos

I tried debugging below module.


When below statement was called, nothing was returned to the variable entity.

This is the reason of the error 'TypeError: Cannot read property 'elements' of undefined'.

const entity = csn.definitions[ensureUnlocalized(entityName)]

entityName was 'localized.demo.callcenter.Inquiries', and ensureUnlocalized(entityName) returned 'o.callcenter.Inquiries', which was not in csn.definitions.

Accepted Solutions (1)

Accepted Solutions (1)

Active Contributor

It was my namespace that was causing the issue: demo.callcenter.

ensureUnlocalized method compares the localized table name with below localized prefixes., ....

In my case, localized table name is localized.demo.callcenter.Inquiries and it matches with, so the method truncates the table name, resulting the error.

I changed the namespace to zdemo.callcenter and now it is working fine.

It seems we cannot use namespaces starting with 'de', 'fr', or any other language keys.

Answers (1)

Answers (1)

0 Kudos

Title: ErroreMessage: Non è stato possibile aprire l’app perché il componente SAP UI5 dell’applicazione non è stato caricato.Details: {"info": "Il componente UI5 non è stato caricato per l’intento \"#Action-toappstateformsample\"","technicalMessage": "failed to load 'sap/ushell/demo/AppStateFormSample/Component.js' from ../../../../../test-resources/sap/ushell/demoapps/AppStateFormSample/Component.js: 404 - Not Found\nError: failed to load 'sap/ushell/demo/AppStateFormSample/Component.js' from ../../../../../test-resources/sap/ushell/demoapps/AppStateFormSample/Component.js: 404 - Not Found\n at makeNestedError (\n at requireModule (\n at requireAll (\n at Object.r [as require] (\n at\n at new Promise (<anonymous>)\n at\nCaused by: Error: 404 - Not Found\n at a (\n at XMLHttpRequest.<anonymous> (\n at loadSyncXHR (\n at requireModule (\n at requireAll (\n at Object.r [as require] (\n at\n at new Promise (<anonymous>)\n at"}