cancel
Showing results for 
Search instead for 
Did you mean: 

Error when calling CAP bound action with input parameter from the UI

I533303
Advisor
Advisor
0 Kudos

Hi all,

I have an entity set (Offers) which contains "guest" attribute that should be edited by selecting a desired row and clicking on "Book" button on the list report page .

entity Offers: managed 
{ 
  key ID : UUID @(Core.Computed : true);
  owner : String ; 
  place : String;
  startDate: Date;
  endDate : Date; 
  description : String;
  status: String default 'Available';
  guest : String
}

I am trying to call CAP bound action action from Fiori List report page that takes as input "myguest" and then update the entity field "guest" by selecting a desired row from the list and clicking on "book" button.

after clicking on the Book button I get the Error below

here is my service definition

Service ParkingService {
 entity Offers as projection on pm.Offers actions { 
   action assignGuest(
      @UI.ParameterDefaultValue : in.guest 
      myguest : String 
   );
 };
 annotate ParkingService.Offers with @odata.draft.enabled;
} 

and here is my custom handler

const cds = require('@sap/cds')
module.exports = function () {
 const { Offers } = cds.entities 
 this.on ('assignGuest', async (req)=> { 
  const id = req.params[0],
  gst = req.data.myguest; 
  const n = await UPDATE(Offers,id) 
  .with({guest: gst, status: "booked"}) 
  .where({status:'Available'});
  n > 0 || req.error (404) 
}) 
} 

I would much appreciate any feedback!

Best Regards

Mariam

johannesvogel
Advisor
Advisor
0 Kudos

Hi idman,

could you please share the version of @sap/cds that you're using?

It'll also be helpful, if you start the application with env variable DEBUG=hana in order to print out the SQL statements that the framework sends to the database.

It seems the SQL statement is invalid but it's hard to tell why without any logs.

Best regards,

Johannes

I533303
Advisor
Advisor
0 Kudos

Hi johannesvogel,

Thanks for your answer, I'm using @sap/cds: 5.7.4 and @sap/cds-compiler: 2.11.4

here is the logs

[cds] - POST /service/parking/$batch
[cds] - > READ Offers(ID=08fb8f6f-a4e9-47ba-81d9-cd19b89ae697,IsActiveEntity=true) {
  '$select': 'HasActiveEntity,HasDraftEntity,ID,IsActiveEntity,description,endDate,owner,place,startDate',
  '$expand': 'DraftAdministrativeData($select=DraftIsCreatedByMe,DraftUUID,InProcessByUser)'
}
[cds] - POST /service/parking/$batch
[cds] - > assignGuest Offers(ID=08fb8f6f-a4e9-47ba-81d9-cd19b89ae697,IsActiveEntity=true)/ParkingService.assignGuest 
[cds] - Error: invalid column name: ISACTIVEENTITY: line 1 col 108 (at pos 107)
    at Request.reject (/home/user/projects/FAParkingManagement/node_modules/@sap/cds/lib/req/request.js:65:39)
    at HanaDatabase.module.exports [as _UPDATE] (/home/user/projects/FAParkingManagement/node_modules/@sap/cds/libx/_runtime/db/generic/update.js:82:9)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async next (/home/user/projects/FAParkingManagement/node_modules/@sap/cds/lib/serve/Service-dispatch.js:74:17)
    at async HanaDatabase.handle (/home/user/projects/FAParkingManagement/node_modules/@sap/cds/lib/serve/Service-dispatch.js:72:10)
    at async ApplicationService.<anonymous> (/home/user/projects/FAParkingManagement/srv/parking-service.js:8:19)
    at async next (/home/user/projects/FAParkingManagement/node_modules/@sap/cds/lib/serve/Service-dispatch.js:74:17)
    at async ApplicationService.handle (/home/user/projects/FAParkingManagement/node_modules/@sap/cds/lib/serve/Service-dispatch.js:72:10)
    at async /home/user/projects/FAParkingManagement/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/handlers/action.js:94:16 {
  code: 260,
  sqlState: 'HY000',
  level: 1,
  position: 0,
  query: 'UPDATE parkingmanagement_Offers SET guest = ?, status = ?, modifiedAt = ?, modifiedBy = ? WHERE ID = ? AND IsActiveEntity = ? AND status = ?',
  values: [
    'warda',
    'booked',
    '2021-12-29T10:24:53.491Z',
    'anonymous',
    '08fb8f6f-a4e9-47ba-81d9-cd19b89ae697',
    'true',
    'Available'
  ],
  numericSeverity: 4,
  id: '1557130',
  timestamp: 1640773523338
}
Thanks and best regards,Mariam

Accepted Solutions (1)

Accepted Solutions (1)

johannesvogel
Advisor
Advisor
0 Kudos

Hi idman,

within the implementation of your action, you use this line:

const id = req.params[0]

According to the documentation, req.params returns an object for compound keys. In your case, the variable "id" does not only hold the value for "ID" but also for "IsActiveEntity".

The value for "IsActiveEntity" must not be provided to the query API as the underlying table does not have this column.

It's a bit unfortunate that there is the need for fiddling around with "IsActiveEntity" within your custom handler but as of now there is no better solution. However, we are working on it already.

Long story short, please make sure that the object you provide as second parameter in

  const n = await UPDATE(Offers,id)

does not contain the property "IsActiveEntity" anymore, if it's value is 'true'.

Best regards,

Johannes

I533303
Advisor
Advisor
0 Kudos

Hi johannesvogel,

I've changed the variable id to only contain the "ID" without "IsActiveEntity" by modifiying this line and it works

const id = req.params[0].ID

Thanks for your support

Answers (0)