<?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: Bulk Update in CAP (Node.js) in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/bulk-update-in-cap-node-js/qaa-p/12609092#M4729129</link>
    <description>&lt;P&gt;It turns out, Update does not seem to be able to handle arrays as input at the moment. &lt;/P&gt;&lt;P&gt;There is an easy fix for you though, simply wrap it in a for loop like this.. &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;        for (let upd of arrUpdate) {
            await db.run(UPDATE(Rates).with(upd))
        }&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 10 Jul 2022 10:08:59 GMT</pubDate>
    <dc:creator>martinstenzig</dc:creator>
    <dc:date>2022-07-10T10:08:59Z</dc:date>
    <item>
      <title>Bulk Update in CAP (Node.js)</title>
      <link>https://community.sap.com/t5/technology-q-a/bulk-update-in-cap-node-js/qaq-p/12609089</link>
      <description>&lt;P&gt;Hi CAP Experts&lt;/P&gt;
  &lt;P&gt;&lt;SPAN class="mention-scrubbed"&gt;david.kunz2&lt;/SPAN&gt; &lt;SPAN class="mention-scrubbed"&gt;gregorwolf&lt;/SPAN&gt; &lt;SPAN class="mention-scrubbed"&gt;mariusobert&lt;/SPAN&gt; &lt;SPAN class="mention-scrubbed"&gt;thomas.jung&lt;/SPAN&gt; &lt;SPAN class="mention-scrubbed"&gt;mioyasutake&lt;/SPAN&gt; &lt;/P&gt;
  &lt;P&gt;I am trying to do a bulk update on an entity but getting an error "invalid column name: 0_ID".&lt;/P&gt;
  &lt;P&gt;The entity has only one key field CUID from sap/cds/common.&lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;Update statement:&lt;/STRONG&gt; &lt;EM&gt;"await db.run(UPDATE(Rates).with(arrUpdate))".&lt;/EM&gt;&lt;/P&gt;
  &lt;P&gt;arrUpdate is an array of json objects. In all the json objects I am passing the ID along with other fields to be updated.&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;Expected behaviour:&lt;/STRONG&gt; above query shall update all fields where respective ID exists in the DB table. Or do I need to update each record in a loop? &lt;BR /&gt;&lt;/P&gt;
  &lt;P&gt;PS: It is &lt;STRONG&gt;not&lt;/STRONG&gt; an update on a deep composition.&lt;/P&gt;
  &lt;P&gt;Thanks Kanika&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 17:52:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/bulk-update-in-cap-node-js/qaq-p/12609089</guid>
      <dc:creator>KM11</dc:creator>
      <dc:date>2022-07-08T17:52:00Z</dc:date>
    </item>
    <item>
      <title>Re: Bulk Update in CAP (Node.js)</title>
      <link>https://community.sap.com/t5/technology-q-a/bulk-update-in-cap-node-js/qaa-p/12609090#M4729127</link>
      <description>&lt;P&gt;Can you do a console.log on Rates and arrUpdate? &lt;/P&gt;&lt;P&gt;I bet you have some weird situation where your Rates object or the array have incorrect information.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 18:01:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/bulk-update-in-cap-node-js/qaa-p/12609090#M4729127</guid>
      <dc:creator>martinstenzig</dc:creator>
      <dc:date>2022-07-08T18:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: Bulk Update in CAP (Node.js)</title>
      <link>https://community.sap.com/t5/technology-q-a/bulk-update-in-cap-node-js/qaa-p/12609091#M4729128</link>
      <description>&lt;P&gt;Hi   &lt;SPAN class="mention-scrubbed"&gt;martin.stenzig3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Below are the console.log output of both arrUpdate and Rates(entity).&lt;/P&gt;&lt;P&gt;Also, is my update statement correct as per the syntax?&lt;/P&gt;&lt;P&gt;definition of Rates: const { Rates } = cds.entities(&amp;lt;namespace&amp;gt;);&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;arrUpdate(SimpleArray):&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;"console.log(arrUpdate)" 
[
  {
    ID: 'f62ea6ec-9c53-4159-85db-8b235b4b0ffd',
    prdno: '123456',
    startDate: '2022-07-14',
    endDate: '2022-07-14',
    value: '1.0000',
    comments: 'New Model Rate'
  },
  {
    ID: 'd0473d3d-25eb-499c-a212-d4b32ecaeaa8',
    prdno: '123457',
    startDate: '2022-07-14',
    endDate: '2022-07-14',
    value: '2.0000',
    comments: 'New Model Rate'
  },
  {
    ID: 'e3b7428d-2005-4ce3-93f1-555396066472',
    prdno: '123458',
    startDate: '2022-07-14',
    endDate: '2022-07-14',
    value: '3.0000',
    comments: 'New Model Rate'
  },
  {
    ID: 'daf419dc-8a54-4f3c-8f68-7be9e14a333f',
    prdno: '123459',
    startDate: '2022-07-14',
    endDate: '2022-07-14',
    value: '4.0000',
    comments: 'New Model Rate'
  },
  {
    ID: 'e62b5b1a-66d7-412a-81c7-fc689486b0e6',
    prdno: '123455',
    startDate: '2022-07-14',
    endDate: '2022-07-14',
    value: '5.0000',
    comments: 'New Model Rate'
  }
]
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Rates(entity):&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;"console.log(Rates)"

entity {
kind: 'entity',
includes: [ 'cuid', 'managed' ],
elements: [Object: null prototype] {
ID: string { key: true, type: 'cds.UUID' },
createdAt: date {
'@cds.on.insert': { '=': '$now' },
'@UI.HiddenFilter': true,
'@Core.Immutable': true,
'@readonly': true,
'@odata.on.insert': { '#': 'now' },
type: 'cds.Timestamp',
'@Core.Computed': true,
'@Common.Label': '{i18n&amp;gt;CreatedAt}'
},
createdBy: string {
'@cds.on.insert': { '=': '$user' },
'@UI.HiddenFilter': true,
'@Core.Immutable': true,
'@readonly': true,
'@odata.on.insert': { '#': 'user' },
type: 'cds.String',
length: 255,
'@Core.Computed': true,
'@Common.Label': '{i18n&amp;gt;CreatedBy}',
'@Core.Description': '{i18n&amp;gt;UserID.Description}'
},
modifiedAt: date {
'@cds.on.insert': { '=': '$now' },
'@cds.on.update': { '=': '$now' },
'@UI.HiddenFilter': true,
'@readonly': true,
'@odata.on.update': { '#': 'now' },
type: 'cds.Timestamp',
'@Core.Computed': true,
'@Common.Label': '{i18n&amp;gt;ChangedAt}'
},
modifiedBy: string {
'@cds.on.insert': { '=': '$user' },
'@cds.on.update': { '=': '$user' },
'@UI.HiddenFilter': true,
'@readonly': true,
'@odata.on.update': { '#': 'user' },
type: 'cds.String',
length: 255,
'@Core.Computed': true,
'@Common.Label': '{i18n&amp;gt;ChangedBy}',
'@Core.Description': '{i18n&amp;gt;UserID.Description}'
},
prdno: string { type: 'cds.String', length: 6 },
startDate: date { type: 'cds.Date' },
endDate: date { type: 'cds.Date' },
value: number { type: 'cds.Decimal', precision: 5, scale: 4 },
comments: string { type: 'cds.String', length: 3000 }
}
}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Thanks&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Kanika&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Jul 2022 08:20:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/bulk-update-in-cap-node-js/qaa-p/12609091#M4729128</guid>
      <dc:creator>KM11</dc:creator>
      <dc:date>2022-07-09T08:20:41Z</dc:date>
    </item>
    <item>
      <title>Re: Bulk Update in CAP (Node.js)</title>
      <link>https://community.sap.com/t5/technology-q-a/bulk-update-in-cap-node-js/qaa-p/12609092#M4729129</link>
      <description>&lt;P&gt;It turns out, Update does not seem to be able to handle arrays as input at the moment. &lt;/P&gt;&lt;P&gt;There is an easy fix for you though, simply wrap it in a for loop like this.. &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;        for (let upd of arrUpdate) {
            await db.run(UPDATE(Rates).with(upd))
        }&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 10 Jul 2022 10:08:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/bulk-update-in-cap-node-js/qaa-p/12609092#M4729129</guid>
      <dc:creator>martinstenzig</dc:creator>
      <dc:date>2022-07-10T10:08:59Z</dc:date>
    </item>
    <item>
      <title>Re: Bulk Update in CAP (Node.js)</title>
      <link>https://community.sap.com/t5/technology-q-a/bulk-update-in-cap-node-js/qaa-p/12609093#M4729130</link>
      <description>&lt;P&gt;Thanks Martin. Was just trying to make a bulk update to avoid multiple hits on DB .&lt;/P&gt;&lt;P&gt;But, I think as of yet it is not possible to do a bulk update, atleast in node.js stack.&lt;/P&gt;&lt;P&gt;More answers from the community welcome &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Kanika&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jul 2022 05:48:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/bulk-update-in-cap-node-js/qaa-p/12609093#M4729130</guid>
      <dc:creator>KM11</dc:creator>
      <dc:date>2022-07-11T05:48:06Z</dc:date>
    </item>
    <item>
      <title>Re: Bulk Update in CAP (Node.js)</title>
      <link>https://community.sap.com/t5/technology-q-a/bulk-update-in-cap-node-js/qaa-p/13942979#M4893175</link>
      <description>&lt;P&gt;Just as a remark: This slows down the async process way too much, as you wait for each Promise to resolve before updating the next one.&lt;/P&gt;&lt;P&gt;Instead of:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;        for (let upd of arrUpdate) {
            await db.run(UPDATE(Rates).with(upd))
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Do:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;let promises = []
for (let upd of arrUpdate) {
    promises.push(db.run(UPDATE(Rates).with(upd)))
}
await Promise.all(promises)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2024 08:12:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/bulk-update-in-cap-node-js/qaa-p/13942979#M4893175</guid>
      <dc:creator>CronJorian</dc:creator>
      <dc:date>2024-11-20T08:12:41Z</dc:date>
    </item>
  </channel>
</rss>

