cancel
Showing results for 
Search instead for 
Did you mean: 

SAP CAP Deep Insert on draft table

FabienHenique
Participant
0 Kudos

Hello CAP Community,

I've created a service which is based on deep insert sample from sapmentors.

Draft capabilities has been enabled for a Fiori Element apps and it's working fine.

Since I also need to consume this CAP Endpoint from SAP Integration Suite, I would like to use a post with deep insert, but I got this error:

cannot insert NULL or update to NULL: DRAFTADMINISTRATIVEDATA_DRAFTUUID: 
line 1 col 1 (at pos 0)",
"stacktrace":["Error: cannot insert NULL or update to NULL: 
DRAFTADMINISTRATIVEDATA_DRAFTUUID: line 1 col 1 (at pos 0)",
"at Request.reject 
(/home/vcap/app/node_modules/@sap/cds/lib/req/request.js:65:39)",
"at HanaDatabase.module.exports [as _CREATE] 
(/home/vcap/app/node_modules/@sap/cds/libx/_runtime/db/generic/create.js:38:9)",
"at runMicrotasks (<anonymous>)",
"at processTicksAndRejections 
(node:internal/process/task_queues:96:5)",
"at async next 
(/home/vcap/app/node_modules/@sap/cds/lib/serve/Service-dispatch.js:74:17)",
"at async HanaDatabase.handle (/home/vcap/app/node_modules/@sap/cds/lib/serve/Service-dispatch.js:72:10)",
"at async Promise.all (index 1)",
"at async ApplicationService._handler (/home/vcap/app/node_modules/@sap/cds/libx/_runtime/fiori/generic/new.js:87:3)",
"at async next (/home/vcap/app/node_modules/@sap/cds/lib/serve/Service-dispatch.js:74:17)",
"at async ApplicationService.handle (/home/vcap/app/node_modules/@sap/cds/lib/serve/Service-dispatch.js:72:10)"],"message":"cannot insert NULL or update to NULL: DRAFTADMINISTRATIVEDATA_DRAFTUUID: line 1 col 1 (at pos 0)",
"code":287,"sqlState":"HY000",
"position":0,"query":"INSERT INTO WBService_items_drafts ( Product_Product, ProductDesign, Quantity, unit, ID, parent_ID ) VALUES ( ?, ?, ?, ?, ?, ?, ? )",
"values":["***"],"numericSeverity":4,"id":"1752958",
"#cf":{"string":[{"k":"query",
"v":"INSERT INTO WBService_items_drafts ( Product_Product, ProductDesign, Quantity, unit, ID, parent_ID ) VALUES ( ?, ?, ?, ?, ?, ?, ? )",
"i":0}]}}

Any idea on how I could fix this issue?

FabienHenique
Participant
0 Kudos

Hello community,

In CAP documentation, a dedicated Java section is explaining how to 'bypass draft flow'.

Since my service is running on NodeJS, does anyone know if it's working with this runtime?

If yes, is it only working with PUT/PATCH or with POST as well?

mariya_yordanova
Explorer
0 Kudos

Hi Fabien,

according to the draft choreography for Node.js runtime you can make deep insert on draft not active entity by calling PUT/PATCH. Making a POST with deep insert should throw 405 "Method Not Allowed".

Are you trying to make deep insert on active draft entity ?

Could you please share what is the request query?

Best Regards

Maria

FabienHenique
Participant
0 Kudos

Hello mariya.yordanova,

Thanks for your answer! My requirement is to post a deep entity for a non-existing entity only.

Here is what is did:

a) Clone repo sample from sapmentors

POST call with this payload: OK

{ "identifier": "Header 1", "items": [ { "data": "A" }, { "data": "B" } ] }

b) Add annotation odata.draft.enabled and then, same POST request (section a) : KO

Error 500: Internal Server Error -> Please check log with DRAFTADMINISTRATIVEDATA_DRAFTUUID issue

c) Test with PUT/PATCH : KO

Error 405 : Method PATCH not allowed for ENTITY.COLLECTION or Method PUT not allowed for ENTITY.COLLECTION

How can I go ahead with this?

mariya_yordanova
Explorer
0 Kudos

Hi Fabien,

in order to make a post on draft enabled entity you have to first make a post with empty body.

POST /MyEntity
{}

Then you can update it with deep insert calling e.g :

PATCH  /MyEntity(ID=UUIDofTheEntity',IsActiveEntity=false)/items(ID=ItemsID,IsActiveEntity=false)
{"data": "A"}

After that you have to activate the entity by calling e.g :

POST /MyEntity(ID=UUIDofTheEntity,IsActiveEntity=false)/service.draft.draftActivate

{}

Please check also capire - Troubleshooting (cloud.sap).

Best Regards

Maria

scatudal
Explorer
0 Kudos

I have a very similar issue but with a deep update. I first get a draft created with the following request:

POST http://localhost:4004/ddu-srv/Parents(ID=0db5bb94-675c-4c06-bcef-465fe43ff690,IsActiveEntity=true)/D...
Content-Type:application/json

{"PreserveChanges":true}
I then try to insert a parentChildAssignment with the following post:
PATCH http://localhost:4004/ddu-srv/Parents(ID=0db5bb94-675c-4c06-bcef-465fe43ff690,IsActiveEntity=false)
Content-Type: application/json

{
    "parentChildAssignments": [
        {
            "parent_ID": "0db5bb94-675c-4c06-bcef-465fe43ff690",
            "child_ID": "01583878-38ca-11ec-8d3d-0242ac130012"
        }]
}

I get an error very similar to what's reported above:

SQLITE_CONSTRAINT: NOT NULL constraint failed: 

DeepDraftUpdateService_ParentChildAssignments_drafts.DraftAdministrativeData_DraftUUID in: 

INSERT INTO DeepDraftUpdateService_ParentChildAssignments_drafts ( parent_ID, child_ID ) VALUES ( ?, ? )

For the moment, the only way I managed to work around the problem is by using a function call. That function first gets the DraftAdministrativeData_DraftUUID for the entity with an existing draft. I then do an insert directly in the DeepDraftUpdateService_ParentChildAssignments_drafts table. I do hope that there's a better way out there to do this.

mariya_yordanova
Explorer
0 Kudos

As it is mentioned in capire - Troubleshooting (cloud.sap), the draft implementation is done for supporting the SAP Fiori elements and not all cases are supported. Please use the deep update via navigation (commented above).

FabienHenique
Participant
0 Kudos

Hello mariya.yordanova ,

I did some test based on your proposal.

Step 1 is working, but deep insert with PATCH request is not working.

Request Payload:

"CustomerRef": "52021608", "Items": [

{ "Product_Product": "800880", "Quantity": "7.5" }, 

{ "Product_Product": "800880", "Quantity": "1" } ]

Response:

"error": { "code": "500", "message": "Internal Server Error" }

I have the same error (cannot insert NULL or update to NULL: DRAFTADMINISTRATIVEDATA_DRAFTUUID).

Any other way to bypass draft table?

Accepted Solutions (0)

Answers (1)

Answers (1)

Nparaman1
Newcomer
0 Kudos

Hi, I'm getting a similar error. How did you resolve it?