Updating tags for Item - How to do?

Hello everybody.

I m starting to use tags. While assigning tags at beginning is OK, I got some problems to updated tags in case the user wants to modify the tags on the selected item.

I followed the How-To, I created the data details area and the api that retrieve the tags for the item.
I made the form with a database update made like this:

“estratto” is the table who contains the items to which tags will be associated.
“tags” is the table who contains the Tags names.
“estrattotags” is the subtable which contains IDs for estratto and for tags

as $_POST variables I set
Schermata 2022-12-20 alle 09.44.06

I tried to set S_POST as array too but I always fgot ERROR 500.
Any hint please ?

Define tags as an array on the post variable

Hi @scalaris,
thank you for your feedback.

I got an error because update was empty (no field of the main table updated). So I had a field that doesn’t use in the record and inserted a text that will be updated.

The api return 200 but unfortunately nothing change on the subtable and tags are not updated.
Any hints ?

Schermata 2022-12-20 alle 19.52.54

You need to use a repeat block with the array of tags and insert them one by one in the repeat using $value (the output fields are unlikely to populate). Check the array.count() isn’t 0 beforehand

You can use $value in the insert query.

Also, you need to delete all tags beforehand

1 Like

Like that ??

Schermata 2022-12-20 alle 20.11.46

What $value is? it is the value of the single item inside the array?

Now I added the insert query in the repeat like that:

And in the $_POST got new array:

Schermata 2022-12-20 alle 20.16.44

More or less. I’d suspect that tag_id should be set to $value.

No idea what the other field is.

Try it. And set the insert query output flag to true so you can debug

Before doing any sort of Database Manipulation I recommend you use Set Value to see if you’re grabbing the variables correctly and view those in the browser’s network tab

1 Like

Done it… thank you very much.

At the end was much easier than expected:

Just added Database DELETE (to delete all the previous tags)
then the repeat on the array
and Database INSERT using $value

Schermata 2022-12-20 alle 20.35.51

Update is not to be used in this case! Just delete and insert.

Thank you very much and special Merry Christmas @scalaris

Cool. Well done. :+1:

1 Like

Yes, I did it :wink:

2 Likes