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

**URL:** <https://forum.bubble.io/t/include-javascript-variable-in-bubbles-search-for-function-toolbox-plugin/311989>\
**Category:** Need help\
**Created:** [March 12, 2024, 11:18am UTC](https://forum.bubble.io/t/include-javascript-variable-in-bubbles-search-for-function-toolbox-plugin/311989 "2024-03-12T11:18:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabriel.guerin](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/gabriel.guerin/32/174949_2.png) [@gabriel.guerin](https://forum.bubble.io/u/gabriel.guerin)\
**Post date:** [March 12, 2024, 11:18am UTC](https://forum.bubble.io/t/include-javascript-variable-in-bubbles-search-for-function-toolbox-plugin/311989/1 "2024-03-12T11:18:55Z")

</div>

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](https://forum.bubble.io/t/using-input-argument-in-javascript-function/122397).

Thank you!

 ![TinySnap-2024-03-12-12.17.20](https://us1.discourse-cdn.com/bubble/original/3X/a/d/ad3c7bb7be39de0a83ec41ed2341581a28e8f1fb.png)

---

<div class="post-metadata">

**Author:** ![adamhholmes](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/adamhholmes/32/100510_2.png) [@adamhholmes](https://forum.bubble.io/u/adamhholmes)\
**Post date:** [March 12, 2024, 11:24am UTC](https://forum.bubble.io/t/include-javascript-variable-in-bubbles-search-for-function-toolbox-plugin/311989/2 "2024-03-12T11:24:29Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![jonah.deleseleuc](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/jonah.deleseleuc/32/199133_2.png) [@jonah.deleseleuc](https://forum.bubble.io/u/jonah.deleseleuc)\
**Post date:** [March 12, 2024, 11:54am UTC](https://forum.bubble.io/t/include-javascript-variable-in-bubbles-search-for-function-toolbox-plugin/311989/3 "2024-03-12T11:54:21Z")

</div>

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 💯 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

---

<div class="post-metadata">

**Author:** ![gabriel.guerin](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/gabriel.guerin/32/174949_2.png) [@gabriel.guerin](https://forum.bubble.io/u/gabriel.guerin)\
**Post date:** [April 10, 2024, 9:46am UTC](https://forum.bubble.io/t/include-javascript-variable-in-bubbles-search-for-function-toolbox-plugin/311989/4 "2024-04-10T09:46:14Z")

</div>

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:

```auto
["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?

 ![TinySnap-2024-03-12-12.17.20](https://us1.discourse-cdn.com/bubble/original/3X/a/d/ad3c7bb7be39de0a83ec41ed2341581a28e8f1fb.png)

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 🙂.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/bubble/original/3X/2/8/2847faa74692c2ffa5d939d3dc3724cdd060d247.png) [@system](https://forum.bubble.io/u/system)\
**Post date:** [May 21, 2024, 11:19am UTC](https://forum.bubble.io/t/include-javascript-variable-in-bubbles-search-for-function-toolbox-plugin/311989/5 "2024-05-21T11:19:41Z")

</div>

Closed on May 21, 2024, 11:19am UTC

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