cancel
Showing results for 
Search instead for 
Did you mean: 

How do I set the Attribute isActiveEntity to true in one call?

Animatron56
Participant

We have implemented an application which is based on SAP Fiori Elements. The application holds onto an entity which consists of Subaccount information. The information in the subaccount entity should be editable by a user in a GUI but should also be passed to the db via an API. Therefore we have implemented the subaccount entity with draft mode enabled. With this the frontend is editable like we want it to.

Our Subaccount entity / service looks something like this:

entity Subaccounts : managed, cuid {<br>subaccountId: String;
globalAccountId: String; 
owner: String;
status: String; 
}

annotate Subaccounts with @odata.draft.enabled;
---
service Account {
entity Subaccounts as projection on db.Subaccounts;
}

Before we pushed data to our db we read the following CAP Article how we can directly create the entity withour generating a draft version before: https://cap.cloud.sap/docs/java/fiori-drafts#bypassing-draft-flow

Now when we try to post a new Subaccount to our DB we tried to do it in the following way.

[POST] */account/Subaccounts<br>
{
  "IsActiveEntity": true,
  "subaccountId": "RANDOM_SUBACCOUNT_ID",
  "globalAccountId": "RANDOM_GLOBAL_ACC_ID",
  "owner": "Tester123",
  "status": "active"
}

After we have send the post, we received a 201 Created response, but get the following feedback, where isActiveEntity is set to false:

{

"@odata.context": "$metadata#Subaccounts/$entity",

"createdAt": "2023-03-02T10:05:47.698Z",

"createdBy": "Tester“,

"modifiedAt": "2023-03-02T10:05:47.698Z",

"modifiedBy": „Tester“,

"ID": „THIS_IS_A_RANDOM_CUID“,

"subaccountId": "RANDOM_SUBACCOUNT_ID",

"globalAccountId": "RANDOM_GLOBAL_ACC_ID",

"owner": Tester123“,

"status": "active",

"IsActiveEntity": false,

"HasActiveEntity": false,

"HasDraftEntity": false

}

With this we only get the a draft version of the pushed entry. But since we know that this entry can be directly set to true we dont want to make another call.

We have found out how to do it in 2 calls by calling .draftActivate, but this does seem like a bad practice to do 2 calls instead of 1.

Does somebody know how I can create an entry in a draft enabled fiori elements applications via the api?

alespad
Contributor
0 Kudos

Hi, I have the same issue: the "Bypassing the SAP Fiori Draft Flow" seems documented only for Java.

I'm using Node.js and passing "IsActiveEntity": true in the payload seems not working.

It's not easy to explain to a third party that should call the api using this draft mechanism, but at the same time we want to use the same service we use for the Fiori App,

do you have any updates?

Thanks

Animatron56
Participant

alessandro.spadoni SAP responded in the ticket, that with node.js it is not possible to bypass draft mode.

alespad
Contributor

bad news... thanks for your answer

Accepted Solutions (1)

Accepted Solutions (1)

Animatron56
Participant

If anyone else is facing this issue:

The SAP responded that bypassing the draft mode in node.js is currently not possible. Currently this is only possible for java applications.

petergilberg
Participant
0 Kudos

Hi,

I worked around this by duplicating the entity and using the annotation @cds.redirection.target: true. I don't know, if this is best practice, still work in progress for me.

Cheers,

Peter

Answers (1)

Answers (1)

TiagoAlmeida
Participant
0 Kudos

I agree. This should be possible. I wonder how recent those features for "Bypassing the SAP Fiori Draft Flow" are in CAP and if your CAP version is older than this?

One workaround (which is not perfect) but better than making two separate calls is to use a single $batch HTTP call where you send the creation and draft activation requests inside the payload. At least you save the round trip time of another HTTP call.

Are you using CAP Java or CAP Node.js ?

Animatron56
Participant

Hello tiago.almeida2 ,

thank you for the feedback. We have also tried it with the latest cap verison which also did not work in one call, so as you said it could be that the documentation is not up-to-date.

We are using CAP Node.js.

I think I have to open up a ticket for this.