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

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

Thanks for your recommendations @keith. There is no reason the data needs to be loaded in the update function though. The docs makes no assertion to that point and actually note that Bubble will continue reloading the data in an action the same way it does in the update function on the element.

Now this 'Try’:point_down:

‘Catches’ the crux of the issue as I have not been accounting for the ‘not ready’ special error from Bubble resulting in it being caught and

  1. Throwing an error that isn’t really an error
  2. Keeping Bubble from doing its background fetch magic.

@wxm I’ve moved the data loading outside the try… catch and pushed an update to the plugin. Very interested to see if this solves your issue.

There is probably a use case for the element itself to find an index anytime the value changes without running the action but that’s for another day.

In case anyone is wondering how I solved this, I used the Toolbox Plugin’s JavaScript to Bubble element and a Run JavaScript workflow. In that workflow, I saved the value of a search for IDs of blocks in the way I wanted them ordered in a variable and then used .indexOf(desiredId) to get its position.

tldr; I just used the Toolbox Plugin as an escape hatch to work around the problem

1 Like

Hi @Eli can you add Grouping as a data type?

I have a Grouping with my RG, and I want to find an index of a specific grouping.

Hey @george8, how would you see identifying the group? There’s no id associated with Bubble’s grouping so I’m not sure how this would work.

Ah good point!

I found a workaround, no biggie.

1 Like

Nice. How will this be any different than the index syntax found natively in bubbles repeating groups, and how is it better?