Forum Academy Marketplace Showcase Pricing Features

Send custom object/data type to Action

TL;DR How do I send a full bubble data type object to an Action? Or a custom JSON object with many custom properties?


I have a custom plugin with Action that takes a lot of data. I know I can define all those fields in the Action’s Fields, but that’s A LOT, and then I’d have to pass them in one-on-one in a Workflow/Event. That seems like a lot of work. I’d rather let the Event choose what to send. Maybe a custom JSON object, or a full Bubble data type object.

I’ve created an Action Field with Editor = Dynamic Value, and Type = any thing with fields, and I can assign its value perfectly in an Event, BUT its practically empty in the Action function:

{"single_api":true}

None of the actual Bubble data in there, so that doesn’t work. I’ve also accessed specific properties in the object, in case it has magic accessors or something, but these are empty:

properties.residu['name']
properties.residu['Name']

How do I send a full bubble data type object to an Action? Or a custom JSON object?

Action Field in plugin:

Passing in data in Event:

2020-08-02_01-20-21

(name, value1 and value2 work, because they take specific properties (string and number))

1 Like

Hello @bubble31,

I encounter the same exact problem for an application.

You can pass your data type and get it back via ‘properties’ argument.
The {"single_api":true} log hides a complex object.

You can access your data fields by doing the following.
const dataFields = properties.residu.listProperties()
let myData = {}
for (const f of dataFields) { myData[f] = myData.get(f)}

This schema is not complete, has JSON objects can be nested one in an other, but you can see the point.
I’ve discovered this, based on action documentation : currentUser access and methods.

I hope it will help

Hi @arnaud.brun.vidal,

I discovered this thread by chance, after stumbling on {"single_api": true} myself.
I tried to apply your solution, but unfortunately, it doesn’t work for me: I get an error back (via an alert) saying that listProperties is not a function.

This happens in the case I try the method on the list of things but it actually works if I do it on a single thing.

In my case this works fine:

const things = properties.things.get(0, properties.things.length());
const thing = thing[0];

return {
    return_value: JSON.stringify(thing.listProperties())
}

To see what is there, simply display the result into an alert.

You are right @alfie.gordon.

Some object doesn’t have the listProperties() method, because they are not real objects (a collection of key/value pairs).
This is the case for arrays objects, which are lists of basic types, or real objects.

So to be really precise on the subject, if the property is an object, use the listProperties() method, else, use the get(0, properties.things.length()) to retrieve all elements of the list.

I also discovered this plugin jsoNest.
It allows to transform valid data as JSON strings representation of your data.
So you can say your plugin takes a string as argument, and cast back this string as a valid JSON object with the JSON.parse() method and everything works fine.

They have a really cool demo to illustrate the purpose of the plugin.

1 Like