Datastore delete item problem

Hi everyone,
I have to solve a problem about deleting an item from a datastore.
I'll explain the flow...
I have a repeat that reads data from a Json file with this structure.

{
  "items": [
    {
      "productcode": "BP-HW-001",
      "price": "4500",
      "image": "assets/images/order/brainpod-personal.png",
      "title": "BrainPod© Personal",
      "description": "Versione entry level ideale per un massimo 3 utenti contemporanei"
    },
    {
      "productcode": "BP-HW-002",
      "price": "6500",
      "image": "assets/images/order/brainpod-team.png",
      "title": "BrainPod© Team",
      "description": "Versione ideale per un massimo 30 utenti contemporanei"
    },
    {
      "productcode": "BP-HW-003",
      "price": "2500",
      "image": "assets/images/order/brainpod-onpremise.png",
      "title": "BrainPod© On-Premise",
      "description": "Installa BrainPod© all'interno del tuo data ceter aziendale"
    }
  ]
}

When I click on an element I write the data into a datastore which has this structure

Data is saved correctly

When I click again I should check if there is already an item with the same product code inside the datastore.
If there is, I have to delete it, otherwise I have to add it.
I created this condition but I think I didn't write the logic well because it doesn't work, it always continues to add the record in the datastore

I think the.value is wrong...

Try to ask for the productCode in your where formatter
swData.data.where(productCode,productcode,'==')[0].productCode

1 Like

Great now it works, thanks for the tip!!

Can I ask you how can I insert the productCodes present in a datastore into a variable as an array?

Insert all the productCodes that exist in your datastore in an array?

Can you please explain?

I would like to read the productcodes from the datastore and transform them into arrays to insert them into a hidden field of a form.

Senza titolo

BP-SK-002;BP-SK-001

I think you can do that with flatten formatter

swData.data.flatten('productCode')

I tried but unfortunately it doesn't work
At the moment I managed to get all the content with the .toJSON formatting but I only need the productcode value

swData.data.join( ',' , 'productCode').splt(',')

In this case it returns me an object

so you want to display it with 1 call...
Try this

swData.data.values(`productCode`)
1 Like

Thanks, this works fine!

1 Like