cancel
Showing results for 
Search instead for 
Did you mean: 

Error when creating several entries CAP

smorenod
Explorer
0 Kudos

Hi experts!!

I'm trying to save several entries in my external service, but it isn't work.

When i execute INSERT sentence for one register it works and it's saved in the database:

await tx.run((INSERT.into(location_sync, [{Werks: 'tes2', Stand:'test', Ktext: 'test'}])));

But when i try to do the same for a table of objects, the error is the same, returns 400 status Bad request: error while deserializing payload.

I have revised whole the fields and it seems it's all okay.

This is the csn imported from external service:

      "kind": "entity",
      "@cds.persistence.skip": true,
      "elements": {
        "Werks": {
          "key": true,
          "type": "cds.String",
          "length": 4
        },
        "Stand": {
          "key": true,
          "type": "cds.String",
          "length": 10
        },
        "Ktext": {
          "type": "cds.String",
          "length": 40
        }
      }

And this is the cds in the original service:

entity location_sync {
    key Werks : String(4);
    key Stand : String(10);
        Ktext : String(40);
}

Do you have some idea?

Thanks in advance!

Best regards

Accepted Solutions (0)

Answers (2)

Answers (2)

leoirudayam
Advisor
Advisor
0 Kudos

Do you know if your external service allows $batch requests? Since, INSERT with multiple rows is using in the background a batch request.

However, you could try to make a foreach on your array and each entry shall be a single insert into. Be aware here about creating multiple Promises and resolve them all at once to avoid a waiting period since you otherwise do an await for each entry.

gregorw
Active Contributor
0 Kudos

Please try with:

INSERT.into(location_sync).rows(arrayWithLocationSyncData)
smorenod
Explorer
0 Kudos

thanks Gregor, yeah i tried with that too and fails, I think the problem is that the service is an extarnal service, and what it's trying to do is a POST with multiples entities and it's not support.

There is some option to execute the insert inside a loop?