1 Thing Plugin - Index Finder - Get the index number for any item in your list

Just tested it and it’s working WONDERS!
It’s being used in a competitive app where I’ll update participants on their current rank.

Thank you so much for this useful little tool!

1 Like

Glad it’s helpful!




I am having trouble getting this plugin to work. Any advice on what I am doing wrong? I saw that in a previous comment you said to run the action in another native bubble event, but still have the A Find Index is Found event ( I assume nothing in it). Can’t get the index number to show up (I double checked to make sure the constraints were correct as well, but it still doesn’t pull up any index #. Any help is greatly appreciated! @eli

@kngf222 the way you have it setup looks correct. Is the element visible on the page before this workflow is run?

The FindIndex element is visible on page load and so is the text box that is displaying the current index of the element. However, they are both in a group that starts out as invisible on page load. However, that group becomes visible and in the same workflow is the find index action. However, the group becomes visible before the find index action.

That should be still work but I would try putting the find index element somewhere on the page so it is visible on page load and not inside a hidden group to see if that solves your issue.

Secondarily, you may try displaying the error result of the element to see if it is returning an error.

Third, it could be the item is not being passed into the action. Bubble recently wrote this on another post:

Read more here: Tip: Order of Operation - #2 by aschofer

I tried what you suggested and it still didn’t work. I found List Shifter and tried their “Get Index” action but that didn’t work either. Not as clear how to use that plugin but either way it still didn’t work, so I am not sure what the reason is for this. Is there some setting I need to change? All my datatypes are public

Edit: I also tried doing the Find Index on a page load and passed the condition to run the action, but it still didn’t show the index number/where it was in the database. It just says “oops, there was an error” or something like that when I do the step-by-step and that is what it shows in the error tab for the Find Index

hey @eli , this plugin has been great! I was wondering if you had a way to add a feature…

I am trying to compile averages for indexes of items in 160 lists. Is there any way to run this on many different lists like this? For example, I want the indexes of all items with a certain name value in this list of lists.

Right now i think the only way is to set up a recursive workflow… but i’d really like to just have a one step process :slight_smile:

Thanks!

Hi @eli thank you for making this plugin! Very useful. However, it seems a bit buggy? I went through the steps above and read the article on order of operations. But it seems as if the plugin is hit or miss.

Any thoughts? Loom | Free Screen & Video Recording Software

I’m getting the “Oops, something went wrong” error.

Digging in a little, it seems to be caused by running list_of_things.length()

But I’ve never worked on a Bubble plugin so I’m pretty lost now. Any ideas what’s causing this error?

Oddly, it is only broken the first time it’s run. If I run it a second time, the error goes away. There needs to be a delay of at least 400ms though.

Hey @brenton.strine,

The “oops something went wrong” error is normally caused by a timeout loading the data. I definitely think that’s the issue here since it’s working the second time through. Likely because the data is already loaded to the page from the first attempt.

I would try to preload the data by setting a custom state or a hidden repeating group and that should solve the issue.

1 Like

I’m also encountering problems trying to use this plugin. Are there any video examples?

In short, I’ve got an app with “blocks” that each have a value. In the page for each individual block, I want to display it’s global rank (e.g. Search for “block”, sort by “value”, descending “yes” and then get the index).

I’ve created a “FindIndex A” element on the page and put a “Find Index FindIndex A” into the workflow for that page under when Page is loaded. Here’s what it looks like:

Screen Shot 2022-04-05 at 12.04.00 PM

And here are the settings:

Screen Shot 2022-04-05 at 12.04.25 PM

Nothing displays in the FindIndex A element when I load the page, but if I use the inspector and step through slowly, I can see that an index of 55 is found (for the block I’m looking at) but the element isn’t visible.

I tried adding another workflow of “When FindIndex A is found” to show FindIndex A. This seems to have no effect. Also, if I don’t use the debugger to step through slowly on page load, instead of an index of #55, the item has an “oops something went wrong error”. (either way, nothing displays).

Any ideas?

@wxm try adding a condition to the page loaded event when ‘Find index a is visible’. What’s likely happening is that the action is running before the element has been drawn on the page.

1 Like

Great idea! I added the condition:

Screen Shot 2022-04-06 at 8.04.46 AM

Unfortunately, the situation is the same. Stepping through with the debugger, there’s a list of blocks found via the search in the FindIndex A (sorted by value) and the block of the page is among them. It looks like it should work.

But after clicking next, the inspector closes. Reopening it and looking for the FindIndex A element, there’s an error and it’s not visible.

I tried one more thing, which was changing the FindIndex A to search for the (list of blocks, sorted by value)'s unique IDs and comparing that with the unique ID of the current page block. Here it’s apparent from the inspector that the current page block IS in the list. For some reason, it still leads to an error and the element being invisible.

So the ‘error’ state is simply a custom state on the plugin. The state will exist whether or not an error has occurred. If it’s empty then no error was returned from the plugin code. If it’s not empty an error occurred in the plugin code.

This screenshot looks like it ran properly as the index # returned was 1 and there is no error.

According to the list of things and the thing to find (from the screenshot with unique ids) the correct index should be 1.

This screenshot looks like it ran properly as the index # returned was 1 and there is no error.

As I said above, that element has an “oops something went wrong” error when I run it normally. It’s only when I step through manually with the debugger, that an index is found (and it still doesn’t display on screen, only in the inspector).

As you suggested, I suspect that there’s a timing issue, but adding a “when FindIndex A is visible” criteria to the workflow didn’t fix it.

Is there a way to do the equivalent of a DOMContentLoaded event callback and have that trigger the index calculation and subsequent update of the text element that displays it?

There are many other ways to do indexOf and maybe you should try one of those. (List Shifter, for example, has an indexof action that triggers an event when the find is complete… it also works on any type of list). Or just write that yourself.

I’ve put a crazy amount of time into this one issue already. Just giving up and not understanding how or why it’s breaking isn’t very appealing.

That said, if you have a specific recommendation and it’s a bit better documented, I’ll try it right away.

The problem with Eli’s plugin is that it will not work properly with long lists. (He should be loading the list on update, because Bubble may repeatedly attempt to load such lists until the page/data is fully loaded.) So, if you have a long list, his plugin will fail because he only tries to load the list when the action runs… and he doesn’t do this before trying .indexOf() on the array, he does it in a “try” clause.

@eli, like the docs say, load your data (do this in update) and THEN attempt your action.

Which is to say: Your update function should retrieve both of the fields provided in the main interface (the list and that scalar). Save them to instance.data.something (e.g., instance.data.list and instance.data.scalar)… and then your action should simply return instance.data.list.indexOf(instance.data.scalar).

1 Like