How to find out prefix or suffix of a field

I have created a new data field called “SelectedProducts” from the editor “Data Tab”
When creating a plugin, from the documentation as described below, I assume I can get the value like:

var value = context.currentUser.get('SelectedProducts');

context = {
     currentUser: {
         get: function(fieldName: String) - returns the value of a field for the object
         listProperties: function() - returns an array of the different fields you can access 
     request: call request with a node request function, returns the response synchronously
     async: call context.async with a function that kicks off an asynchronous operation, 
         taking a callback taking (err, res). Returns res or else throws error.
     keys: Object with Keys defined in the Plugins Tab

But instead when I do ‘listProperties()’, the fieldName is actually something like ‘selectedproducts_list_api_apiconnector2_bTGPS0_bTGPT0_data_search_contents’

So instead I should do:

var value = context.currentUser.get('selectedproducts_list_api_apiconnector2_bTGPS0_bTGPT0_data_search_contents');

How do I actually know what are the “prefix” or “suffix”?
I doubt is going to stay the same when there are changes to the App

Weeeellll, yes and no. If you’re building a plugin SPECIFIC to your app (there are good reasons for doing this), you might do that.

But if you’re building a general use plugin, you don’t know, in advance, what properties the User object might have and your plugin should not usually care about them.

Inputs to the plugin are presented via fields in the plugin interface, which are then presented to the plugin’s internals as properties of the (unsurprisingly named) properties object.

In general, we access those fields just once (on instantiation of the plugin) and move things over to the instance object (as properties of… because all of your other action functions get instance sent to them.

So for example, while there are things we can do in function initialize (which is called just once) — like set up some aspects of the canvas (if our plugin is an element with visual features) — we get the main properties object only in function update (which gets called AFTER function initialize).

So anyway, the thing you’re looking at (which is something sourced from an API Connector call, obviously), is not accessed via the User property of context. Instead, the plugin has an interface field of some type — where the Bubble developer user will present to us a value (which might be User’s some-whatever-we-don’t-know-or-care-What-it-is).

But the plugin will now see that as properties.some-thing-we-Do-know.

So, for example: Let us say we have a field where the Bubble dev will send us info about “number of cats”.

In the plugin builder, we will define a field captioned “Number of Cats”, which will become properties.number_of_cats to function update. (Let’s also assume this field is optional.)

There (in function update), we will do something like:

properties.number_of_cats ? = properties.number_of_cats : ( = true, = null)

Now, the Bubble dev might send number of cats as a scalar (5), as an expression (User’s CatList:count), or as the result of a search (Do a Search for… Cats [constraint Created By Current User]), or as the result of an API call (Get Data from API… CatSearch… parameters blah blah blah)… and we don’t care.

To us, and to the plugin, all of these just yield us a number we can use in our plugin’s internals — properties.number_of_cats.

(Lists — arrays — require special handling using the list API explained in the documentation for properties.)

So that’s how you generalize stuff. If you’re building a plugin specific to some single app, you might do what you’re suggesting, but in that case why build a plugin? (Just do what you need to do in Bubble.)

Thanks for the elaborate reply, appreciate it.

What I am trying to do is grab a list of items (in JSON) from external API, and show them on the page (Currently using ‘Repeating Group’). The JSON returned from the API looks something like:

   "items": [
       { "id": "001", "name": "Some name1", "sub": { "sub_id1": "A", sub_name": "sub2" } },
       { "id": "002", "name": "Some name2", "sub": { "sub_id1": "A", sub_name": "sub2" } }

The user can then select some of the items from the ‘Repeating Group’ and I want to do something with the user selected items.

I don’t need any of the data to store in Database, but I couldn’t figure out how as it seems like every piece of complex data needs to be a “Thing” (I am new to Bubble)

I first tried to store the selected items as custom state, but after scouring through the forum seems like “adding” and “removing” from custom state is not possible yet. (Since 2016)

So I ended up adding the selected items to Current User custom field I have created. So that I can add and remove the items the users choose to add or remove.

At this point, I haven’t figure out besides using Plugin how else I can grab the selected items and do something with it. I simply want to run some Javascript and combine the items to:

<ul><li>001: Some name1</li><li>002: Some name2</li></ul>

and return it as String.

Yeah, you don’t need a plugin for that.

Not exactly on your use case, but you should watch this video, where I pull data from an API(s) and just plop it right into an RG, without storing anything in the database. I talk about that along the way…

Hey, great video, I haven’t finished it yet.

But yeah, I am able to pull data from external API and plop it in RG without issues, and the only reason I am storing it in Database is that I want to process the selected items from the RG.

I have tried putting it in custom state but currently custom state doesn’t support adding and removing items.

So I ended up storing the “Selected items on RG” in Database.

And then have my custom Javascript do something about it.