Skip to content

submitOrder: set IsActiveEntity to true - #48

Open
vl-leon wants to merge 4 commits into
mainfrom
submit-order-set-active-entity
Open

submitOrder: set IsActiveEntity to true#48
vl-leon wants to merge 4 commits into
mainfrom
submit-order-set-active-entity

Conversation

@vl-leon

@vl-leon vl-leon commented Jul 28, 2026

Copy link
Copy Markdown
Contributor
  • set the newly created entity instance to be active, by default it will be inactive

@vl-leon
vl-leon requested a review from chgeo July 28, 2026 11:15
@chgeo
chgeo requested a review from johannes-vogel July 28, 2026 11:35
Comment thread srv/mashup.js
Items: [{ product:{ID:`${book}`}, title, price, quantity }],
buyer, createdBy: buyer, currency
buyer, createdBy: buyer, currency,
IsActiveEntity: true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johannes-vogel @sjvans is this the recommended pattern?

@vl-leon vl-leon Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://cap.cloud.sap/docs/guides/uis/fiori#requests-to-active-data

Add IsActiveEntity=true as a key parameter to your requests to address active data directly

, for POST(CREATE) too

https://cap.cloud.sap/docs/guides/uis/fiori#draft-agnostic-requests

Taking this further, through cds.fiori.draft_new_action: true IsActiveEntity=true is assumed by default, so clients that are unaware of drafts or don't need to handle them can ignore all draft-specific requests and parameters

The cds.fiori.draft_new_action feature is currently not enabled in the orders module.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be active by default, as you're creating a Orders and not a Orders.drafts

how can i reproduce?

@vl-leon vl-leon Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to reproduce it follow the steps:

  • prepare the repository

For more details on @capire modules, see Using @capire modules from GitHub Packages.

git clone https://github.com/capire/orders.git
cd orders
npm login --scope @capire --registry=https://npm.pkg.github.com/
npm i
npm i -D @cap-js/sqlite
npm i -D @cap-js/cds-test
  • create a new file named odata.create.order.active.by.default.test.js with content:
const cds = require('@sap/cds')
const { POST, expect, defaults } = cds.test(".", '--with-mocks')

describe ('OrdersService', () => {

  beforeAll (()=> {
    cds.requires.queue = { timeout: '1h' }
    defaults.auth = { username: 'alice' }
    defaults.path = '/odata/v4/orders'
  })

  it('create active order by default', async () => {
    const { data: data1 } = await POST(`/Orders`, {
      'OrderNo': 'active',
      //IsActiveEntity: true // uncomment to fix
    })
    expect (data1.OrderNo) .to.equal ('active')
    expect (data1.IsActiveEntity) .to.equal (true)
  })

})
  • run the test to get error
npx jest odata.create.order.active.by.default.test.js
  • uncomment line 15 to fix the test
....
IsActiveEntity: true // uncomment to fix
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants