<?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: CUID causes error with custom event handler on CAPM (NodeJS) in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/cuid-causes-error-with-custom-event-handler-on-capm-nodejs/qaa-p/12793143#M4803193</link>
    <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;afsal_a&lt;/SPAN&gt; ,&lt;/P&gt;&lt;P&gt;At the end of your `init` method, please add `return super.init()`.&lt;/P&gt;&lt;P&gt;Best regards,&lt;BR /&gt;David&lt;/P&gt;</description>
    <pubDate>Tue, 28 Nov 2023 11:06:02 GMT</pubDate>
    <dc:creator>david_kunz2</dc:creator>
    <dc:date>2023-11-28T11:06:02Z</dc:date>
    <item>
      <title>CUID causes error with custom event handler on CAPM (NodeJS)</title>
      <link>https://community.sap.com/t5/technology-q-a/cuid-causes-error-with-custom-event-handler-on-capm-nodejs/qaq-p/12793142</link>
      <description>&lt;P&gt;Hi, &lt;BR /&gt;I am trying to implement a sample application with custom implementation logic.&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;schema.cds&lt;/EM&gt; looks like&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt; using {&lt;BR /&gt;  managed,&lt;BR /&gt;  cuid,&lt;BR /&gt;  User,&lt;BR /&gt;  sap.common.CodeList&lt;BR /&gt;} from '@sap/cds/common';&lt;BR /&gt;namespace afs.csupport;&lt;BR /&gt;....&lt;BR /&gt;entity Users : cuid, managed {&lt;BR /&gt;  firstName: String;&lt;BR /&gt;  lastName: String;&lt;BR /&gt;  email: EMailAddress @assert.format : '[\w.]+@[\w.]+';&lt;BR /&gt;  phone: PhoneNumber;&lt;BR /&gt;  _tickets: Association to many Tickets on _tickets._author = $self;&lt;BR /&gt;  _assigned: Association to many Tickets on _assigned._assignedTo = $self;&lt;BR /&gt;}&lt;BR /&gt;.....&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;&lt;EM&gt;myservice.cds&lt;BR /&gt;&lt;BR /&gt;&lt;/EM&gt;&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;&lt;EM&gt;using {afs.csupport as my} from '../db/schema';&lt;BR /&gt;&lt;/EM&gt;&lt;EM&gt;service CustomerService @(path:'/service'){&lt;BR /&gt;&lt;/EM&gt;&lt;EM&gt;......&lt;BR /&gt;&lt;/EM&gt;&lt;EM&gt;    entity users     as projection on my.Users;&lt;BR /&gt;&lt;/EM&gt;&lt;EM&gt;}&lt;/EM&gt;&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;&lt;BR /&gt;so far, POST, GET , DELETE operations works fine when tested in with postman.&lt;BR /&gt;&lt;BR /&gt;but, when I added the &lt;EM&gt;myservice.js&lt;/EM&gt; for testing custom implementation and event handling, the POST request failed and I got the following error in terminal&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;[odata] - POST /service/users &lt;BR /&gt;[cds] - TypeError: Cannot read properties of undefined (reading 'ID')&lt;BR /&gt;    at UriHelper.buildEntityKeys (C:\SAPDevelop\csupport\node_modules\@sap\cds\libx\_runtime\cds-services\adapter\odata-v4\okra\odata-server\utils\UriHelper.js:85:22)&lt;BR /&gt;    at ResponseHeaderSetter.setLocationHeader (C:\SAPDevelop\csupport\node_modules\@sap\cds\libx\_runtime\cds-services\adapter\odata-v4\okra\odata-server\core\ResponseHeaderSetter.js:102:17)&lt;BR /&gt;    at SetResponseHeadersCommand.execute (C:\SAPDevelop\csupport\node_modules\@sap\cds\libx\_runtime\cds-services\adapter\odata-v4\okra\odata-server\invocation\SetResponseHeadersCommand.js:66:30)&lt;BR /&gt;    at CommandExecutor._execute (C:\SAPDevelop\csupport\node_modules\@sap\cds\libx\_runtime\cds-services\adapter\odata-v4\okra\odata-server\invocation\CommandExecutor.js:71:17)&lt;BR /&gt;    at C:\SAPDevelop\csupport\node_modules\@sap\cds\libx\_runtime\cds-services\adapter\odata-v4\okra\odata-server\invocation\CommandExecutor.js:81:18      &lt;BR /&gt;    at ConditionalRequestControlCommand.execute (C:\SAPDevelop\csupport\node_modules\@sap\cds\libx\_runtime\cds-services\adapter\odata-v4\okra\odata-server\invocation\ConditionalRequestControlCommand.js:48:5)&lt;BR /&gt;    at CommandExecutor._execute (C:\SAPDevelop\csupport\node_modules\@sap\cds\libx\_runtime\cds-services\adapter\odata-v4\okra\odata-server\invocation\CommandExecutor.js:71:17)&lt;BR /&gt;    at C:\SAPDevelop\csupport\node_modules\@sap\cds\libx\_runtime\cds-services\adapter\odata-v4\okra\odata-server\invocation\CommandExecutor.js:81:18      &lt;BR /&gt;    at C:\SAPDevelop\csupport\node_modules\@sap\cds\libx\_runtime\cds-services\adapter\odata-v4\okra\odata-server\invocation\DispatcherCommand.js:88:11    &lt;BR /&gt;    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {&lt;BR /&gt;  id: '1591466',&lt;BR /&gt;  level: 'ERROR',&lt;BR /&gt;  timestamp: 1701164783226&lt;BR /&gt;}&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;myservice.js&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;const cds = require("@sap/cds/lib");&lt;BR /&gt;module.exports = class CustomerService extends cds.ApplicationService {&lt;BR /&gt;  init() {&lt;BR /&gt;    this.on("CREATE", "ticket", (req, next) =&amp;gt; {&lt;BR /&gt;      const data = req.data;&lt;BR /&gt;      if (data.title.length &amp;lt; 10) return req.reject("The title is too short");&lt;BR /&gt;      else return next();&lt;BR /&gt;    });&lt;BR /&gt;    this.on("READ", "ticket", (req, next) =&amp;gt; {&lt;BR /&gt;      return next();&lt;BR /&gt;    });&lt;BR /&gt;    this.on("CREATE", "users", (req, next) =&amp;gt; {&lt;BR /&gt;      return next();&lt;BR /&gt;    });&lt;BR /&gt;  }&lt;BR /&gt;};&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Since the ID field is a cuid that is autogenerated, I am not passing that to the request. &lt;BR /&gt;Did I miss anything in the implementation file that supports the database level auto generated field.&lt;BR /&gt;&lt;BR /&gt;here is the payload&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;{&lt;BR /&gt;    "firstName":"Alice",&lt;BR /&gt;    "lastName":"Warner",&lt;BR /&gt;    "email":"alice@abc.com",&lt;BR /&gt;    "phone":"9999548765"&lt;BR /&gt;}&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Nov 2023 10:02:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/cuid-causes-error-with-custom-event-handler-on-capm-nodejs/qaq-p/12793142</guid>
      <dc:creator>Afsal</dc:creator>
      <dc:date>2023-11-28T10:02:00Z</dc:date>
    </item>
    <item>
      <title>Re: CUID causes error with custom event handler on CAPM (NodeJS)</title>
      <link>https://community.sap.com/t5/technology-q-a/cuid-causes-error-with-custom-event-handler-on-capm-nodejs/qaa-p/12793143#M4803193</link>
      <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;afsal_a&lt;/SPAN&gt; ,&lt;/P&gt;&lt;P&gt;At the end of your `init` method, please add `return super.init()`.&lt;/P&gt;&lt;P&gt;Best regards,&lt;BR /&gt;David&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2023 11:06:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/cuid-causes-error-with-custom-event-handler-on-capm-nodejs/qaa-p/12793143#M4803193</guid>
      <dc:creator>david_kunz2</dc:creator>
      <dc:date>2023-11-28T11:06:02Z</dc:date>
    </item>
    <item>
      <title>Re: CUID causes error with custom event handler on CAPM (NodeJS)</title>
      <link>https://community.sap.com/t5/technology-q-a/cuid-causes-error-with-custom-event-handler-on-capm-nodejs/qaa-p/12793144#M4803194</link>
      <description>&lt;P&gt;Thanks  &lt;SPAN class="mention-scrubbed"&gt;david.kunz2&lt;/SPAN&gt; ,&lt;BR /&gt;That worked.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2023 14:27:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/cuid-causes-error-with-custom-event-handler-on-capm-nodejs/qaa-p/12793144#M4803194</guid>
      <dc:creator>Afsal</dc:creator>
      <dc:date>2023-11-28T14:27:33Z</dc:date>
    </item>
  </channel>
</rss>

