Skip to Content
3
Mar 02 at 01:46 PM

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

313 Views Last edit Mar 02 at 01:52 PM 8 rev

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?