添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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)
  

schema.cds:

entity SecurityEmployeeTypes: managed, temporal {
  key ID: UUID @(Core.Computed : true, title: 'ID');
  shortTxt: localized String(60) @(title: 'Short text');
  descr: localized String(1000) @(title: 'Description');
  dayRate: Decimal(6,2) @(title: 'Rate at day');
  nightRate: Decimal(6,2) @(title: 'Rate at night');
  bankholidayRate: Decimal(6,2) @(title: 'Rate at bank holiday');
  

srv/my-service.cds:

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:

  srv.on("NEW", SecurityEmployeeTypes, (req, next) => {
    req.data.validFrom = new Date();
    return next()

Best regards,
David

Hi david.kunz2,

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:
[cds] - POST /browse/$batch
[cds] - > PATCH SecurityEmployeeTypes(ID=9088c4af-904f-410c-959f-414b73176ef7,IsActiveEntity=false)
[cds] - POST /browse/$batch
[cds] - > PATCH SecurityEmployeeTypes(ID=9088c4af-904f-410c-959f-414b73176ef7,IsActiveEntity=false)
[cds] - POST /browse/$batch
[cds] - > PATCH SecurityEmployeeTypes(ID=9088c4af-904f-410c-959f-414b73176ef7,IsActiveEntity=false)
[cds] - POST /browse/$batch
[cds] - > PATCH SecurityEmployeeTypes(ID=9088c4af-904f-410c-959f-414b73176ef7,IsActiveEntity=false)
[cds] - POST /browse/$batch
[cds] - > PATCH SecurityEmployeeTypes(ID=9088c4af-904f-410c-959f-414b73176ef7,IsActiveEntity=false)
[cds] - POST /browse/$batch
[cds] - > draftPrepare SecurityEmployeeTypes(ID=9088c4af-904f-410c-959f-414b73176ef7,IsActiveEntity=false)/SeccalcService.draftPrepare
[cds] - > draftActivate SecurityEmployeeTypes(ID=9088c4af-904f-410c-959f-414b73176ef7,IsActiveEntity=false)/SeccalcService.draftActivate {
  '$select': 'HasActiveEntity,HasDraftEntity,ID,IsActiveEntity,bankholidayRate,dayRate,descr,nightRate,shortTxt',
  '$expand': 'DraftAdministrativeData($select=DraftIsCreatedByMe,DraftUUID,InProcessByUser)'
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)?

Thanks and best regards,
David

TypeError: Cannot read properties of undefined (reading 'concat') in Technology Q&A Error when creating an action in CAP project: Cannot read properties of undefined reading (_target) in Technology Q&A cds add http produced this error message: TypeError: Cannot convert undefined or null to object in Technology Q&A How to retrieve data from a fieldymbol nested of deep structures in Technology Q&A ERROR: Upgrading @cap/cds and @cap/cds-dk to version 8 in Technology Q&A