What are Bubble's "Things" in javascript? I can't retrieve "Current User" as an object or as anything else. How to translate bubble stuff into JS elements?

I’m trying to extract a Current User’s name through a console.log(???); to begin with.

I thought a Bubble thing was an object, but it doesn’t seems to be, because it throws a lot of errors when I try to manipulate a Thing as an object, and currently console.log’ing it returns this:

{…}  ​

__original: function __original()    ​

get: function get()    ​

listProperties: function listProperties()
​
__proto__: Object { … }

And when I try to Object.entries() it:

  […]  ​

    0: Array [ "get", get() ]    ​

    1: Array [ "listProperties", listProperties() ]    ​

    2: Array [ "__original", __original() ]    ​

    length: 3
    __proto__: Array []

Putting this question in another way:

Does this:

Translates into this?

Horta = {

Catalogo_Padrao: [ { }, { }, ... ],     //array of objects?

lista_de_texto: ["lalala", "something else", ""....] ,   // array of strings?

Nome: "lalalla",    // simple string?

Modified_date: "05/09/2018"   //simple string?

}

Because I want to handle those things with javascript.

Did you manage to find out?

1 Like

Yep.
Every thing is an object.
And in a plugin, when you want to get a value stored in a thing’s field, you use:

console.log(properties.someThing.listProperties());  // Will list fields for me
console.log(properties.someThing.get("Created Date"));  // Will return the date
console.log(properties.someThing.get("lista_de_texto_list_text"));  // Will return the list of texts (an array)
2 Likes

Thanks! Can you push a value? Or do you have to go through the native functions provided via workflow?

Push a value where? Into the database inside a thing? Not through this channel, this is a getter object only. We don’t set values this way.
Bubble has some features to save to database, but none that I know of to simply shove some data into the app maker’s database without the app maker’s manual input.

Client side we can publish something into a state of an element in a page via

instance.publishState("saved_pdf", url)

and then the app maker gets the value there.

Server side we use “Result of step X…”, when step X is the step that runs the server side workflow, like this:

“ssss” is my server side action. This is what I know that works. Since Bubble doesn’t provides setter functions… I think this is it.

Edit: In short, no. We can’t directly touch the database, but apart of native workflows we can touch it through the Data API, but it’s much more complicated on my view.

1 Like

Thanks for the detailed reply! I will start working with this tomorrow.

Hmm? Current User is always available via context:

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
}
jQuery: main jQuery object
uploadContent: function(fileName: String, contents: Base64 String, callback: function(err, url), [attachTo])
attachTo: optional parameter to attach the file to. It has to be a thing in Bubble
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
onCookieOptIn: function(callback: function - runs callback once cookies are allowed (immediately if already accepted)
reportToDebugger: function(message: String) - reports an error to the debugger
}

Hey @keith, would you mind elaborating what you wrote?

I am writing a javascript script which has to call an API in my app and supply current user’s id to it.

I am guessing what you have written would be useful to me, but I am unable to understand what exactly I need to do. Is “context” an in-built keyword in javascript? Is currentUser a variable that is available to us in the scripts? What you have written is kind of pseudo code I think. Could you share what could be the code snippet exactly? I am not using jQuery by the way.

Are you suggesting that I write the code below and I’ll get user’s email in “currentUser”?

context = {
      currentUser: {
                  get: function (email:String) {
                  }
}

I was quoting the docs. Current user is always available via the context object. That is all.

Okay. I think I stepped on wrong thread. This looks like is for plugin builders and what you said might be evident to them.

I guess I’ll have to keep searching for what I need. Thanks for your reply @keith

Where is your JavaScript going to sit - inside your app or externally somewhere?
Context is only available within the scope of a Bubble plugin.

1 Like

I am going to use it within my app only. But would be in a file that is loaded at some places conditionally.

Yes, I realised I posted in wrong thread. I somehow thought it matched my requirement.