How to recursively change a Field within a set of Things after deleting one item in that set?

How can I recursively change a Field within a set of Things after deleting one item in that set?

For example:

I have a set of Things, each with a serial number Field that increases +1 incrementally with each new entry.

If I then delete an item from that set, for example the 3rd one, which is to say the one with a serial number == 3, then the resulting set’s serial number Fields will run in the following sequence: 1, 2, 4, 5

So now it would seem appropriate to “Make Changes to a Thing”, but I am not sure how I should structure that -

@emmanuel I feel in my heart you will know the answer to this :slight_smile:

Honestly what you’re trying to do isn’t super clear… After you delete the 3rd one, you would want to move from 1, 2, 4, 5 to 1, 2, 3, 4? Is that right?

@emmanuel you understand me rightly there.

Initially the values increase incrementally & sequentially:

1, 2, 3, 4, 5, 6 … n

Then we delete one row and create a gap in the sequence

1, 2, [deleted], 4, 5, 6, 7, 8 … n

What we want to do then is from the deleted item’s index onward (in this case the 3rd item, which currently has a value of “4”), subtract 1 to recreate the correct sequence without any gaps, ie

1, 2, 3, 4, 5, 6 … n

I am certainly not Emmanuel (biggest understatement ever), but I have done this exact thing before, so I will throw something out there as food for thought.

You have to make changes to a list of things before you delete the item. So, you make changes to a list of things where the serial numbers are greater than the serial number of the item you are deleting (which you won’t be able to determine if you have already deleted that item), and the change you make to those items is to subtract 1 from their serial numbers. Then, when that action is complete, you delete the initial item and you should be all set.

Does that make sense?

Best…
Mike

@mikeloc

The principle of what you describe makes perfect sense. The question now is how to apply that logic to more than just the “Current Cell” of the Repeating Group?

Implementing the logic in this manner, by resetting (I think) the next cell’s value to == the current cell’s value, successfully alters the Current Cell but seems to do the same for all subsequent Cells, e.g.

1, 2, 3, 4, 5, 6 … n

just becomes:

1, 2, 3, 4, 4, 4, 4 …

where exercise == {Thing} and Category == {Field}

… as you can see here:

In your first screenshot, I believe the expression to change the category field should be something like category = This exercise's category - 1. Are you able to construct that expression?

1 Like

Yeah I would do as @mikeloc describes

1 Like

@mikeloc You are exactly right. Resolved! Thanks.

Awesome… happy to help!

Best…
Mike

This was the final configuration:

2 Likes