I'm using CAP node runtime with sqlite database and have an issue with temporal data.
When creating an instance of the following entity I get this error:
[INTERNAL ERROR] TypeError: Cannot read property 'ID' of undefined
at Function.buildEntityKeys (/home/helmut/projects/tammenit/security-calc/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/utils/UriHelper.js:84:22)
at ResponseHeaderSetter.setLocationHeader (/home/helmut/projects/tammenit/security-calc/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/core/ResponseHeaderSetter.js:100:17)
at SetResponseHeadersCommand.execute (/home/helmut/projects/tammenit/security-calc/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/SetResponseHeadersCommand.js:66:30)
at CommandExecutor._execute (/home/helmut/projects/tammenit/security-calc/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/CommandExecutor.js:71:17)
at /home/helmut/projects/tammenit/security-calc/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/CommandExecutor.js:81:18
at ConditionalRequestControlCommand.execute (/home/helmut/projects/tammenit/security-calc/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/ConditionalRequestControlCommand.js:49:5)
at CommandExecutor._execute (/home/helmut/projects/tammenit/security-calc/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/CommandExecutor.js:71:17)
at /home/helmut/projects/tammenit/security-calc/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/CommandExecutor.js:81:18
at /home/helmut/projects/tammenit/security-calc/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/DispatcherCommand.js:92:11
at processTicksAndRejections (internal/process/task_queues.js:95:5)
using {de.tammenit.securitycalc as db } from '../db/schema';
service SeccalcService @(path:'/browse') { entity SecurityEmployeeTypes as projection on db.SecurityEmployeeTypes excluding {createdBy, modifiedBy}; annotate SecurityEmployeeTypes with @odata.draft.enabled; }
srv/my-service.js
const cds = require("@sap/cds");
module.exports = async (srv) => {
const { SecurityEmployeeTypes } = srv.entities;
//Fill property validFrom, when a new SecurityEmployeeTypes is created
srv.on("NEW", SecurityEmployeeTypes, async (req) => {
req.data.validFrom = new Date();
Do I get the error cause temporal data isn't supported very well for SQLite?
The documentation only says that time-travel and time-period queries are not supported by SQLite. The rest should work, shouldn't it?
Thanks in advance Helmut
Hi helmut.tammen2 ,
In your `new` handler, you need to return the correct result:
thanks, the error disappeared. I copied the new handler from this SAP repo: [email protected]:SAP-samples/fiori-elements-feature-showcase.git. There is also no 'return next();'
srv.before('NEW',RootEntities, async (req) => {
req.data.contact_ID = (await SELECT.one.from(Contacts, contact => {contact.ID})).ID; //Default Contact to prevent Error when creating address label
//Generating chart entities, so the charts are not empty - the user has no option to fill in chart entity values in the UI
req.data.chartEntities = [];
for(let i = 1; i <= 10; i++) {
req.data.chartEntities.push({
ID : cds.utils.uuid(),
parent_ID : req.data.ID,
uom_code : 'EA',
dimensions : i,
integerValue : i+30,
forecastValue : i*2+35,
targetValue : i*1.6+36,
criticality_code : i % 4,
DraftAdministrativeData_DraftUUID : req.data.DraftAdministrativeData_DraftUUID
As said, the error disappeared but the data is not saved to the database even though I get the success message 'Object has been saved' as a MessageToast.The console also does not show an error:
Will have a deeper look at it on monday. Thanks so far and have a nice weekend. Helmut
Hi helmut.tammen2 ,
The difference is that in the feature showcase a before handler is used (where all on handlers are called afterwards, returning the correct result), here you overwrite the on handler, therefore you need to take care that the correct result is returned.
Can you post the SQL statements (by setting DEBUG=sqlite or DEBUG=hana)?