What is the best way to access a list of things, do operations and publish result in a list?

Hi bubblers ! :smiley:

When I started building some apps with bubble I didn’t think I would learn Javascript and also create some plugins.
4-5 months later, I think have good skills with JS (for a beginner). And I succeeded to build some toy plugins.
(A thousand thanks to @vini_brito to publishing open source plugins. It was by looking at your code that I understood how we make plugins).

Usually, I find the solution by reading the bubble manual or looking on the forum. But here, I am completely lost…

I’m trying to build a client side action that access a list of things, test the value of this things and publish the result (as things) in a list.

Here is what I did to try to understand :


This simple script test numbers in DB before « theNB »

  1. Firstly, how can I deal with « app type » ?
    For instance, if I define a type in the editor, the following fields are not restrict to this type.

  2. Secondly, how can I tell to Bubble : I want you to check all this things and the value to check is… ?
    In this exemple, I told to Bubble to searching all ’nb’ in the things « nb to check » (in DB). But how can I have retrieve the thing relative to this thing ?
    That is to say, must I define a field in my plugin « treat only with all this things », and a second field in my plugin « treat with this value in the things ».

  3. Finally, how can I return a list of things (in this case return a list of things of ’nb to check’) instead of returning the list of tested number (in this case it’s return [nb1, nb2…]?
    According to different Bubble post, I’m right if I say that client side action can’t return data (« result of step X ») ? (without use this tips : Output an object for server-side/client-side )
    Is it possible to return this list of thing « nb to search » in a custom state « list of nb to check » and use this list with the excellent list shifter plugin from @Keith ?

Or maybe i’m totally wrong and I should use an element and place the result as an exposed state ?

Hope my English is good :clipperton_island:

Cheers :smiley:

1 Like

(1)
When you create an ‘App Type’ field it’s Name is added to the Type list in all subsequent Dynamic Value fields. So, in your listNBToCheck field you will find a Type called “type” (yes, confusing, as your field name is “type”…), and setting Type to “type” will limit the input to the result of the App Type field.

(2)
I’m not sure I understand the question here. Are you asking how you retrieve Things that might be linked to another Thing. So, for instance, if your search results return a list of linked Things, how do you then get values from those (linked) Things?

Or something else?

(3)
The cleanest way to do this is with Exposed States. You define these in the Plugin Editor beneath your Fields section. It is just like defining a field - give it a data type etc.

Then in your code you can set (or change) the value of an Exposed State any time with the following code:
instance.publishState(“stateName”, value); where value is the variable / data that you want to set the state to. If you have defined the Exposed State to be a list then you can publish a list / array as the value.

This Exposed State will then be readable from within Bubble as an attribute of the element.

Hi there,
I tried to follow your advice for (3).
I publish my array
instance.publishState(“specification_object”, resarray);

When following my code, I can see it has values:

But it returns empty results.