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

EKEYTYPE: The key argument has to be of type `string` or `number`. Found: `undefined` in CAP.

Boopalan
Explorer
1,484

Hi Experts!

GoodDay!

This issue was raised in between the development (when adding attachment feature to my CAP application – used @cap-js/sdm library as mentioned in CAPIRE documentation)

Below is the structure of my header and attachment entity.

InvoiceHeader – Entity

Boopalan_0-1730193033591.png

Attachment – Entity

Boopalan_1-1730193033592.png

I’ve implemented a custom handler for InvoiceHeader entity on Update event.

Boopalan_2-1730193033594.png

I’m running my application in a hybrid mode and I’m opening my annotated UI application (built using FPM). When trying to edit a record and saving it showing me the below error.

             EKEYTYPE: The key argument has to be of type `string` or `number`. Found: `undefined`

Boopalan_3-1730193094690.png

When I’m debugging it, the error was coming from the SELECT statement (which was working previously) line no.103 like in the below screenshot. However the query executed successfully where you can see the result in aHeaders variable.

Boopalan_4-1730193094697.png

I’m sure “ID” is the only key for InvoiceHeader Entity and the value is coming via “req.data.ID” parameter.

I’m trying to figure it out, I’m not sure where I’m lagging.

Help me to resolve this issue.

Thanks in Advance!!

Best Regards

Boopalan M

SAP Business Application Studio , SAP Cloud Application Programming Model ,

SAP HANA Cloud , SAP HANA Cloud, SAP HANA database 

Accepted Solutions (1)

Accepted Solutions (1)

catano
Active Participant
0 Kudos

Hi @Boopalan ,

Have you tried the complete configuration as described in the documentation?

I just tried the setup you described. I received the same error message you do by just adding the npm library and extending the model with the extra attachments field.
In debug I see, that the referenced id in the error message is the repository id of the sdm repository (SAP Document Management).
I added the following configuration to the package.json:

"sdm": {
   "settings": {
   "repositoryId": "<repository-Id>"
   }
}

and I stopped getting the error message.

Regards,
Peter

pedro_iranzo
Product and Topic Expert
Product and Topic Expert
0 Kudos

Indeed, in my case I had a wrong repository ID set. Just for reference, from the docs:

Create a SAP Document Management Integration Option Service instance and key. Using credentials from key onboard a repository and configure the onboarded repositoryId under cds.requires in package.json. Currently only non versioned repositories are supported.

pedro_iranzo
Product and Topic Expert
Product and Topic Expert
0 Kudos
Indeed, in my case I had a wrong repository ID set. Just for reference, from the docs:

Answers (2)

Answers (2)

catano
Active Participant
0 Kudos

Hi @Boopalan ,

Could you take a look at the Serving Media Data topic in the documentation? 

entity Books { //...
  image : LargeBinary @Core.MediaType: imageType;
  imageType : String  @Core.IsMediaType;
}

Maybe that's what you are looking for instead of the attachments and sdm plugins.

Regards,
Peter

catano
Active Participant
0 Kudos

Hi @Boopalan ,

Have you tried to remove the key keyword from Parent? The Attachments entity itself already has a key ID inherited from the cuid aspect.
I haven't tried your whole setup, but as a first shot maybe could you try like this?

entity C_Attachment : Attachments {
  name: String;
  Parent: Association to one InvoiceHeader;
}

Also the Attachments has a filename property inherited from the MediaData aspect if you could use that.
You can inspect all the aspects of the Attachments entity in Business Application Studio / VSCode by Ctrl + Click in Win (or Cmd + Click in Mac)

Regards,

Peter

Boopalan
Explorer
0 Kudos

Hi @catano

I've tried what you've mentioned. However, it didn't help me resolve the issue.
Thanks for the suggesting the aspects. The name : String is experimental.

Do you have any other idea?

Best Regards,

Boopalan M

 

catano
Active Participant
0 Kudos
Do you have a different error message if you try to run the query on the model where you only removed the key keyword?
Boopalan
Explorer
0 Kudos

@catano, it is showing the error as before. When I remove the attachments composition from the header entity, it is working as expected while update event.

I've followed the same step as mentioned in the documentation CAP Plugins & Enhancements | capire

Rather than wrapping the Attachment aspects in C_Attachment, I've made the direct composition of Attachment aspect to attachments field in Header entity.

Screenshot for your reference

Boopalan_0-1730228350558.png

however, it is showing the same error at the select statement as before.

Is it a bug in CAP? or am I missing something important?