<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Programmatically trigger draft events in CAP in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/programmatically-trigger-draft-events-in-cap/qaa-p/13922721#M4890359</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Do you think these events you describe could be replaced by plain CRUD requests?&lt;BR /&gt;For example activate with a READ draft and a CREATE non-draft call, or discard with a DELETE draft call?&lt;BR /&gt;The reason I ask is because if using a * event listener to see what is running under the hood as a result of draft create, update and create from draft, these are pretty much what is happening.&lt;BR /&gt;Is there a reason why you can't use these?&lt;/P&gt;&lt;P&gt;Peter&lt;/P&gt;</description>
    <pubDate>Tue, 29 Oct 2024 14:04:05 GMT</pubDate>
    <dc:creator>catano</dc:creator>
    <dc:date>2024-10-29T14:04:05Z</dc:date>
    <item>
      <title>Programmatically trigger draft events in CAP</title>
      <link>https://community.sap.com/t5/technology-q-a/programmatically-trigger-draft-events-in-cap/qaq-p/13917481</link>
      <description>&lt;P&gt;We have a use case in CAP where we are programmatically triggering draft events (create, prepare, activate, discard). &amp;nbsp;We were able to do this for the "create" draft event via the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const { draftEntity } = service.entities
const payload = {}
await service.send({query:INSERT.into(draftEntity).entries(payload), event: 'NEW'})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately we have not been able to figure out how to trigger the prepare, activate, and discard events. &amp;nbsp;We have tried the following and various iterations with no success: &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const { draftEntity } = service.entities

//draftEntityID is the passed in ID for the draft entity we want to activate
await service.send({ event: 'draftActivate', entity: draftEntity, data: {}, params: [{ID: draftEntityID, IsActiveEntity: false}]})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Being able to do this is very important to our overall design. &amp;nbsp;Any suggestions on how to accomplish this would be greatly appreciated!&lt;/P&gt;&lt;P&gt;For reference, here are the CAP relevant versions we are at while trying this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="bash"&gt;-js/asyncapi: 1.0.2
@cap-js/db-service: 1.14.0
@cap-js/hana: 1.3.2
@cap-js/openapi: 1.0.6
@sap/cds: 8.3.1
@sap/cds-compiler: 5.3.2
@sap/cds-dk: 8.3.0
@sap/cds-dk (global): 8.2.2
@sap/cds-fiori: 1.2.3
@sap/cds-foss: 5.0.0
@sap/cds-mtxs: 2.2.0
@sap/eslint-plugin-cds: 3.1.0
Node.js: v18.20.3&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2024 18:31:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/programmatically-trigger-draft-events-in-cap/qaq-p/13917481</guid>
      <dc:creator>Steven-Mason</dc:creator>
      <dc:date>2024-10-23T18:31:29Z</dc:date>
    </item>
    <item>
      <title>Re: Programmatically trigger draft events in CAP</title>
      <link>https://community.sap.com/t5/technology-q-a/programmatically-trigger-draft-events-in-cap/qaa-p/13922721#M4890359</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Do you think these events you describe could be replaced by plain CRUD requests?&lt;BR /&gt;For example activate with a READ draft and a CREATE non-draft call, or discard with a DELETE draft call?&lt;BR /&gt;The reason I ask is because if using a * event listener to see what is running under the hood as a result of draft create, update and create from draft, these are pretty much what is happening.&lt;BR /&gt;Is there a reason why you can't use these?&lt;/P&gt;&lt;P&gt;Peter&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2024 14:04:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/programmatically-trigger-draft-events-in-cap/qaa-p/13922721#M4890359</guid>
      <dc:creator>catano</dc:creator>
      <dc:date>2024-10-29T14:04:05Z</dc:date>
    </item>
    <item>
      <title>Re: Programmatically trigger draft events in CAP</title>
      <link>https://community.sap.com/t5/technology-q-a/programmatically-trigger-draft-events-in-cap/qaa-p/13922726#M4890361</link>
      <description>&lt;P&gt;I tried to craft a request to call &lt;FONT face="courier new,courier"&gt;draftPrepare&lt;/FONT&gt; for example - what is called by the framework by default - but I cannot make it work: even if I have the same query, method, params and everything I still cannot pass &lt;FONT face="courier new,courier"&gt;Symbol(draftParams) = { IsActiveEntity: false }&lt;/FONT&gt; down the stream.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2024 14:06:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/programmatically-trigger-draft-events-in-cap/qaa-p/13922726#M4890361</guid>
      <dc:creator>catano</dc:creator>
      <dc:date>2024-10-29T14:06:49Z</dc:date>
    </item>
    <item>
      <title>Re: Programmatically trigger draft events in CAP</title>
      <link>https://community.sap.com/t5/technology-q-a/programmatically-trigger-draft-events-in-cap/qaa-p/13924275#M4890575</link>
      <description>&lt;P&gt;Thanks Peter,&lt;/P&gt;&lt;P&gt;I have tried sending the "standard" events coming through the system based. &amp;nbsp;For example, I have used "SAVE" instead of draftActivate. &amp;nbsp;Example of this being:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="abap"&gt;const { draftEntity } = service.entities

//draftEntityID is the passed in ID for the draft entity we want to activate
await service.send({ event: 'SAVE', entity: draftEntity, data: {}, params: [{ID: draftEntityID, IsActiveEntity: false}]})&lt;/LI-CODE&gt;&lt;P&gt;While the framework does not reject this, it does not successfully trigger the draftActivate behavior observed from calls to the OData service.&lt;/P&gt;&lt;P&gt;Anyone else have any ideas on what I am doing wrong and how I could do this programmatically?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 20:27:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/programmatically-trigger-draft-events-in-cap/qaa-p/13924275#M4890575</guid>
      <dc:creator>Steven-Mason</dc:creator>
      <dc:date>2024-10-30T20:27:52Z</dc:date>
    </item>
    <item>
      <title>Re: Programmatically trigger draft events in CAP</title>
      <link>https://community.sap.com/t5/technology-q-a/programmatically-trigger-draft-events-in-cap/qaa-p/13924426#M4890609</link>
      <description>&lt;P&gt;If creating a non-draft entity instance of the draft, then what I tried to suggest is do the following steps:&lt;/P&gt;&lt;P&gt;Taking the ID of the draft entity:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;read draft entity data by ID&lt;/LI&gt;&lt;LI&gt;create non-draft entity with draft data&lt;/LI&gt;&lt;LI&gt;update draft data to reflect state after creating non-draft from draft, either delete draft or do any necessary status change of draft&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;This is just an idea, I don't know if it is feasible or not without knowing the complete scenario of yours.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Oct 2024 06:04:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/programmatically-trigger-draft-events-in-cap/qaa-p/13924426#M4890609</guid>
      <dc:creator>catano</dc:creator>
      <dc:date>2024-10-31T06:04:53Z</dc:date>
    </item>
    <item>
      <title>Re: Programmatically trigger draft events in CAP</title>
      <link>https://community.sap.com/t5/technology-q-a/programmatically-trigger-draft-events-in-cap/qaa-p/13924510#M4890615</link>
      <description>&lt;P&gt;I just played around with the stuff, but still have no idea. I could craft the HTTP request to call the draft actions but cannot call them programatically, even when try to fully copy the request made by the framework itself..&lt;/P&gt;&lt;LI-CODE lang="abap"&gt;http://localhost:4004/odata/v4/service/Entity(ID=c2b16e23-d129-4134-9558-1512c75ceb62,IsActiveEntity=false)/Service.draftPrepare
http://localhost:4004/odata/v4/service/Entity(ID=c2b16e23-d129-4134-9558-1512c75ceb62,IsActiveEntity=false)/Service.draftActivate&lt;/LI-CODE&gt;&lt;P&gt;I would assume that the following should work:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;srv.send('GET', `Entity(ID=${id},IsActiveEntity=false)/Service.draftPrepare`);&lt;/LI-CODE&gt;&lt;P&gt;but I'm a bit confused because I cannot even make it work a basic query like:&lt;/P&gt;&lt;LI-CODE lang="abap"&gt;srv.send('GET', 'Entity');&lt;/LI-CODE&gt;&lt;P&gt;I'm still getting error message:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;[cds] - Error: The request has no query and cannot be served generically.
    at module.exports (/Users/petermanuel.catano/projects/sap-btp-cloud-full-stack-challange/node_modules/@sap/cds/libx/_runtime/common/error/index.js:5:48)
    at ApplicationService.&amp;lt;anonymous&amp;gt; (/Users/petermanuel.catano/projects/sap-btp-cloud-full-stack-challange/node_modules/@sap/cds/libx/_runtime/common/generic/crud.js:17:13)
    at next (/Users/petermanuel.catano/projects/sap-btp-cloud-full-stack-challange/node_modules/@sap/cds/lib/srv/srv-dispatch.js:69:36)
    at ApplicationService.handle (/Users/petermanuel.catano/projects/sap-btp-cloud-full-stack-challange/node_modules/@sap/cds/lib/srv/srv-dispatch.js:73:6)
    at async ApplicationService.handle (/Users/petermanuel.catano/projects/sap-btp-cloud-full-stack-challange/node_modules/@sap/cds/libx/_runtime/common/Service.js:84:16)
    at async ApplicationService.&amp;lt;anonymous&amp;gt; (/Users/petermanuel.catano/projects/sap-btp-cloud-full-stack-challange/srv/service.js:124:18)
    at async next (/Users/petermanuel.catano/projects/sap-btp-cloud-full-stack-challange/node_modules/@sap/cds/lib/srv/srv-dispatch.js:69:17)
    at async ApplicationService.handle (/Users/petermanuel.catano/projects/sap-btp-cloud-full-stack-challange/node_modules/@sap/cds/lib/srv/srv-dispatch.js:67:10)
    at async ApplicationService.handle (/Users/petermanuel.catano/projects/sap-btp-cloud-full-stack-challange/node_modules/@sap/cds/libx/_runtime/common/Service.js:84:16) {&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Oct 2024 06:11:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/programmatically-trigger-draft-events-in-cap/qaa-p/13924510#M4890615</guid>
      <dc:creator>catano</dc:creator>
      <dc:date>2024-10-31T06:11:51Z</dc:date>
    </item>
  </channel>
</rss>

