How to insert data in between indexes in local data-store?

Hello guys. I need help on how to insert data into data-store in between indexes / ids, for example;

$id
1
2
3
<-- I want to insert data here
4
5

so expected result should be
$id
1
2
3
4
5
6

Thanks in advance.

Here is how I can go about it using JavaScript:

  1. Get the data already stored in the data-store. You can use
    let data = dmx.app.data.dataStoreName.data

  2. User the splice() method in JavaScript to insert the new data to the index you want
    data.splice(3,0, yourDataHere)
    In your case at index 3, with a deleteCount of 0 and your then add your new record (yourDataHere)

  3. Now that you have a new dataset, loop through each record and update/add to your data-store with the upsert() method.

Eg:

dmx.parse(`dataStoreName.upsert({$id: ‘${eachrecordid}’, name: ‘${record value}’})

Maybe there are other solutions.

1 Like

The data store component doesn’t support this.
Things like insert after index, replace at index etc. are available in the array component. If the array component is fine for you, you can do the manipulations there, and store the results in the data store when the array value is updated.

Thanks for the confirmation Teodor. In fact I moved from my implementation using array to using data-store instead but now I realised it doesn’t have that feature as the array does even though it has array component which I’m not sure if it’s even functional. Now I need to go back to drawing board and see if I can use array component with data store to achieve what I need. Anyway do you plan to make it possible in the next version of app connect or it’s not even technically not possible? Ty

Thanks kkoker I have no issue implementing using JavaScript but implementing the vanilla with appconnect is quite a mess (and slow) I tried it. If the appconnect flow does support repeat insert data-store with condition it’d be easier to implement and play with more logic.