cancel
Showing results for 
Search instead for 
Did you mean: 

CAP (Node.js) error when running INSERT AS SELECT queries

bdeboer
Explorer

I don't know where else to submit this. I'm trying to run the following query with `@sap/cds 4.1.9`

INSERT.into(MyTable).columns('column1', 'column2').as(SELECT([
	'column1',
	'column2',
	{ val: `'${now.toISOString()}'`, as: "createdAt"},
	{ val: `'anonymous'`, as: "createdBy"},
	{ val: `'${now.toISOString()}'`, as: "modifiedAt"},
	{ val: `'anonymous'`, as: "modifiedBy"}
]).from(MyOtherTable)

which results in the following error:

Exception has occurred: TypeError: Cannot convert undefined or null to object
  at Function.keys (<anonymous>)
    at checkIntegrityUtil (/home/node/app/node_modules/@sap/cds-runtime/lib/cds-services/services/utils/handlerUtils.js:207:14)
    at _performCheck (/home/node/app/node_modules/@sap/cds-runtime/lib/db/generic/integrity.js:71:9)
    ... 

The code fails because context.data is undefined here.

This used to work fine with `@sap/cds 3.x.x`

Accepted Solutions (1)

Accepted Solutions (1)

olena_
Participant
0 Kudos

Hi Bart,

Thank you for bringing this to our attention, it's a problem on our side, will be fixed with the next release.

Just a remark: createdAt, modifiedAt and modifiedBy don't affect anything in your query, maybe you need to change it as follows

INSERT.into(MyTable).columns('column1', 'column2', 'createdAt', 'createdBy', 'modifiedBy').as(SELECT([
	'column1',
	'column2',
	{ val: `'${now.toISOString()}'`, as: "createdAt"},
	{ val: `'anonymous'`, as: "createdBy"},
	{ val: `'${now.toISOString()}'`, as: "modifiedAt"},
	{ val: `'anonymous'`, as: "modifiedBy"}
]).from(MyOtherTable)

Best regards,

Olena

Answers (0)