Trigger a custom event when data changes on a field of type 'List of'

Hello.

I am trying to monitor changes on a field of type ‘List of’, so if a new item is added or deleted from the list, a custom event is fired.

The problem I am encountering is that, as soon as I call the ‘Trigger a custom event when data changes’ (to start monitoring the changes), the custom event is fired, regardless of whether the list has changed.

Is this an expected behaviour?

Many thanks in advance.

Regards.

Hi @miguel :slight_smile: I just tried to set up a “Trigger a custom event when data changes” by monitoring a User’s List of Tags. The editor didn’t present any errors, but I also couldn’t get this to work as expected when a Tag was added or removed from the list. The reference guide states “This action watches a thing for changes to a specific field, and then triggers a custom event workflow when it changes”, so it may only work single field Things, and not for a list of Things? I’m not sure if this is intended, but I agree it would be very helpful to monitor changes to a list of things:count with this type of workflow as well!

Would a setup similar to this example work for your use case? Here, the Current User has a list of Tags, and each time they add or remove a Tag, an alert is shown (but you could run a custom event instead of showing an alert). If so, I can definitely provide more detail about how to set it up :slight_smile:

Preview:

Editor:

2 Likes

Thanks a lot for your answer @fayewatson :slight_smile:

Yes, something like what you’ve done could work for me. Though it’s just a shame that we can’t monitor a List of Things, as I believe it would be quite useful.

Thanks again!

I agree! That would be really useful, especially for automatically scrolling to the bottom of an repeating group of Messages each time a new Message is added (instead of having to set up a custom state to watch the count) :slight_smile:

In the example which watches the Current User’s list of Tags, we first need to set a custom state when the page is loaded to store the total number of Tags in the Current User’s list of Tags. To do this, we can set a custom state for this total number of tags when the page is first loaded:

To set up that custom state (“Total Tags”), I set the custom state on the element “RepeatingGroup MyTags” (but you could choose any element you’d like of course). Since we want to store the number of Tags in the Current User’s list of Tags, I named the custom state “Total Tags” and set it as: (type: number, list: no)

On page load, the value of that “Total Tags” custom state is set to be the Current User’s list of Tags:count.

For example, if the page was loaded and the Current User’s list of Tags:count was 3, this custom state value would be set to 3 (and not change unless we update the custom state again).

In order to ‘monitor’ when there is a change in the Current User’s list of Tags, the “Do When Condition is True” action below is run when the page has fully loaded, and the Current User’s list of Tags:count is not equal to the “Total Tags” custom state value:

Similar to the “Trigger a custom event when data changes” action, this event will run any time there is a change to the Current User’s list of tags:count, since that number will not match the custom state value that was initially set on page load.

For example, if the page was first loaded and the Current User’s list of Tags:count was 3 – then, the Current User removed a Tag from their List of Tags, the Current User’s new list of Tags:count would be 2. However, the custom state would still be set as 3. This would cause the “Do When Condition is True” action to run (since 2 is not 3).
The first action would run (showing the alert), and then the second action updates the custom state from 3 to 2 (in order to match the new, Current User’s list of Tags:count):

Then, if the Current User makes another change (i.e., they subtracted another Tag from their list of Tags, bringing their list’s total from 2 to 1), the “Do When Condition is True” action would run again (since the Current User’s list of Tags:count is 1, and the custom state value was still 2 from before). The alert would show and the custom state would then be updated from 2 to 1 in order to match the Current User’s new list of Tags:count. :slight_smile:

That should work! But feel free to let me know if anything was unclear or if you have any questions!

3 Likes

This topic was automatically closed after 70 days. New replies are no longer allowed.