Hey @ihsanzainal84, it’s great that you reasoned it out. You’re spot on. The only suggestion I would make is to use is not instead of >. That way, either merged or intersection can come first in the expression and one needn’t concern themselves with the direction of the angle bracket. The fact that there’s a count difference is all that matters. It simply indicates the lists are different.
Lists merged:count is not List intersection:count
What’s more, there’s simple logic to determine exactly which items were added and/or removed:
Get the list of items removed
List before:minus list (List intersection)
Get the list of items added
List now:minus list (List Intersection)
I do exactly this in one of my apps. Users can have multiple roles, and I use a DB trigger to execute some logic whenever there’s a change to a user’s roles. I also send an admin notification with the user’s current roles as well as exactly which roles were added/removed.
For anyone interested in learning more, this all has to do with the mathematics of “finite sets”. In Bubble, “merged” is what’s known as a set “union”. An LLM can take it from there.
Just be mindful of sort order, as this approach is nondeterministic with respect to list content alone. That is, it will produce a different output even if the items comprising the list don’t change but their order does.
For example, if the app has logic which overwrites the original list with a reordered copy, such as…
ListItems set list = This Thing's ListItems:sorted by Field
or
ListItems set list = RG's List of ListItems (where RG is sorted)
…then that would result in a modification where the content of the list doesn’t change but the order does.
Of course, it’s easy to account for that by simply sorting each list before formatting as text…
List A:sorted by uid each item's uid join with , is not List B:sorted by uid each item's uid join with ,
This delimited string comparison approach has the advantage of being able to detect a change in order only.
- Either content or order has changed (unsorted list before !== unsorted list after)
- Only content has changed (sorted list before !== sorted list after)
- Only the order has changed (sorted list before === sorted list after AND unsorted list before !== unsorted list after)
If you’re not concerned with the order of items, working directly with lists allows you to determine not just that the lists are different but how they are different.