Forum Academy Marketplace Showcase Pricing Features

How to achieve this list count/uniquification bit in Bubble

I have an app where people perform tasks at different stations.

In the list of stations that they perform tasks at, I want to see how many times do they need to switch the station in a day.

So for example if the list is

I want

So that I can see they have switched station 5 times in a day. And also I can analyse from where to where the movements are happening etc.

Any ideas how to achieve this? (Preferably not via recursive API workflow, but rather something that can be done right away (custom event) and with minimal WUs)

Also, I want to achieve this in backend.

Run some JS via the Toolbox plugin, it will execute on client side.
Here’s something you could do:

var originalList = ['a','a','b','c','b']
var shortenedList = []
for(var x=0; x<originalList.length; x++){
 if(x===0 || (originalList[x] !== originalList[x-1])){

return shortenedList.length;


Use the Toolbox plugin’s expression element, put this code in and access the result as a number from the element.

Thanks Ranjit. Looks good. However, like I had mentioned, I need to do this in the backend. I suppose I can’t do the toolbox plugin thing in the backend workflow?

Also, I showed a,b,c etc as text in the example. They are ideally Bubble’s things and if possible I’d like to use them as is without converting to text.

If absolutely not possible, I can convert them to text using their unique IDs maybe and then can do javascript processing. Even now the solution that I am attempting, in that I am trying to convert these elements to text using unique id and attempting some regex bit (Not javascript but Bubble’s native functions). Not successful so far though.

You can run a backend workflow with NodeJS code via the Toolbox plugin. The function can stay the same - the only thing that changes would be the way you source the contents of the original list in the JS script (which can be done via dynamic data).

Since the JS code can be generated via dynamic data, you don’t have to necessarily change anything to a string, but instead use the :format as text operator via dynamic data. Get your list of things (via a search for example) and apply :formatted as text to it. Here, define the format as the field within this thing you want to use within quotes (something like “this thing’s name”) and use ‘,’ as the separator.

So your JS will start like this:
... var originalList = [Search for things: formatted as text] ....
And the rest can stay the same