Change order of tagify field items (Server Connect)

I know v6 has tagify sorting in it (drag and drop) but I have data in a table which has sort order values and so I want to process them in the set order rather than the order they put them into the tagify field or the order they’ve dragged them into.

Eg. Data is: id, productname, sortorder
1, Product 1, 10
2, Product 2, 20
3, Product 3, 30

Then they fill the tagify field with:
Product 3, Product 1, Product 2

I want the SC actions to store them in the JSON field as [1,2,3]

What’s the process to achieve this? I’ve tried creating an array and repeating through the posted values and populating that array. Then sorting the array by the sortorder field. But I can’t see how I get the new array values into the JSON field in my database.

Hey Jon,

If I understand right, you want the JSON to be rearranged depending on the sortorder of the items that exist in the tagify no matter the order that the have been placed from the user…
Is that right?

Spot on.

The order of the items is already determined in the database. They will add them into the tagify field in whatever order they choose but ultimately they need to be stored in the order set by the data.

How you handle the data at the moment on serverside?
I would like to test it but it would be better if I have something to work on specific…
A screenshot of this part of your serveraction maybe

This is what I’ve done so far. It all seems logical and should work but I just can’t see how I get the finished array into the JSON field in the database.

The array structure is this:

Screenshot 2023-11-28 at 17.23.37

Jon,
I think that I did what you did but my JSON field is reordered…
Please look the last column on line 10
Is this what you want?

  1. JSON field normally update (tagify value)

  2. JSON field reorder update

Wait… Something is wrong
Let me look again

Yes, it’s OK.

Superb. That looks like exactly what I’m after. How did you do it?

Huge thanks for the help.

1 Like

What I did is I think the same with what you did

With one difference…
What is this setValue there?

Here is what I did. (I supposed you want the JSON field to contain numbers instead of strings)

3 Likes

You are an absolute diamond @famousmag. It looks like the bit I was missing was how you set the ‘Set Value’ of {{sortedCats.flatten('catid')}} which I assume has to be hand-coded as I wasn’t able to select sortedCat in order to then format it.

Will give it a go now.

Massive thanks again. Wonderful description and screenshots.

1 Like

Hi again

The Set Value stage was the bit I needed and it’s now fully working.

I hit the issue of the bug in the Sort Array action but downloaded the fix from here:

(I’m still using v5.8.2 for this project)

Thanks again @famousmag.

1 Like