Include Javascript variable in Bubble's "Search for" function (Toolbox plugin)

Hello Bubble Community,

I’m using the “Run javascript” action from the Toolbox plugin within a Javascript loop (in blue), and I’m trying to include a unique ID variable in the “Search for” function. I’ve attached a screenshot where I’ve highlighted in red where I want to include the unique ID. Could anyone guide me on how to reference this variable correctly within the “Do a search for” function?

Here’s a link to a similar post that might shed some light on this issue.

Thank you!

It’s not clear what you’re trying to do here…

But to search for a User by unique ID just enter their unique ID in the search constraint…

(but I get the feeling that’s not what you’re trying to do)

1 Like

Hey there Gabriel,

Your script looks pretty long. This is slightly off topic, but in theory that’s fine, but in practice and in my experience bubble to JavaScript can be an unreliable way to get working :100: of the time. I recommend converting this script into a custom plugin and use a server side action or get the data with an element instead. I believe you’ll run into less headache that way

Best or luck to you

1 Like

Thanks to @adamholmes, I realized that my question wasn’t very clear. Here’s an update:

I need to allow admins to create group chats (including themselves in the group chat) with users they select. These selected users are stored in a custom state called selected_users. Based on this list of users, I create an array of their IDs. Since we are using TalkJS as our chat solution, I need to use javascript to create the group chat (hence the “Run javascript” action).

So I have an array called participantIds which contains user IDs like this:

["1655465590703x437801625069674400","1684692172054x164560990929283430","1654694654190x647166918388294600","1654365395105x480127186784762750","1654857006373x202822646347519520"]

I iterate over this array using the forEach function (highlighted in blue in the screenshot) with the parameter id, which holds an ID from the array, and the index i. For each ID, I need to look up the user associated with it in my Bubble database and return their data, such as name or email address. However, when I pass the id JS variable (from the forEach loop) to Bubble’s “Search for” function, it doesn’t pass the actual ID from the participantIds array (e.g. “1655465590703x437801625069674400”), but just passes id as plain text. How can I make sure I am passing these variables correctly?

I’m sure there’s a cleaner way to achieve this, but for now I’m adding all the user info I need to create my group chat in TalkJS, such as their email, profile picture, etc., into their own array inside the “Run javascript” action, and then I use the i index from the loop to iterate over this array and get the right information.

Please let me know if you need more information :slightly_smiling_face:.

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