cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Error when creating an action in CAP project: Cannot read properties of undefined reading (_target)

alejandro15
Explorer
0 Kudos
336

I encountered an error when trying to create a custom action for my services in my CAP project. Here's some of my code:

My CDS service file:

 

 

using {mySchema as my} from './mySchema';

service myService @(path: '/api/v1/myService') {
    entity mySchema as projection on my.mySchema;
    
    // My custom action
    action myAction(id: Integer) returns String;
}

 

 

My js service file:

 

 

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

class myService extends cds.ApplicationService{
    init() {
        this.on('myAction', async (req) => {
            console.log('Hello from my action');
            console.log(`Id: ${req.data.id}`);

            return 'Hello from my action';
        });
        return super.init();
    }
}

 

 

 

When I executed the following endpoint with PUT in Postman: http://localhost:8080/api/v1/myService/myAction(id=28), I received this error:

 

 

{
    "error": {
        "code": "500",
        "message": "Cannot read properties of undefined (reading '_target')"
    }
}

 

 

alejandro15_0-1729554023815.png

Does anyone know why I'm getting this error or if there's documentation about this? Did I forget to include something?

alejandro15_1-1729555011970.png

 

 

Accepted Solutions (0)

Answers (0)