Plugin builder - how to use defined fields in element action?

Facing a challenge building plugins in bubble. Help appreciated !

On a plugin element:
I have a set of fields on a plugin in ‘Fields’ section. These can be used in the ‘update’ function of the plugin element (as seen on expanding the documentation above the function).

But, on adding a workflow action via the ‘element actions - triggered in workflows’ section, we can’t use the above defined fields for the workflow action function ? That doesn’t seem right.

How do we use the fields in Fields section in the workflow action ?

cc @emmanuel @nickhil @kevin2

hey there @gaurav

If I am understand your issue correctly, you likely need to add some code to the ‘Update’ function to make your standard Fields universally available across all of the functions, including your Workflow function.

To do this you want to commit them to the instance object. The Instance object is always available, so store anything that you need across multiple functions within Instance.data

Here’s an example…
Let’s say you have two fields that you want universally available: Name and Spend

**Update Function**
// commit the Fields to the Instance object
instance.data.Name = properties.Name;
instance.data.Spend = properties.Spend;

**Workflow Function**
// you can now recall and use the fields
if (instance.data.Name === 'Sarah') { do something };

Let us know how you get on.

Ed

3 Likes

Ah I see. That’s very helpful !
Thanks @exception-rambler !!

Btw did you find this by iterating or is there bubble documentation around the instance.data object ?

After passing endless arrays / variables between the Functions for a long time… I reread the documentation on the Editor page (see below) and realised that instance and context were available across all Functions.

There might now be better documentation that highlights that opportunity - it is a core bit of knowledge!

instance = {
canvas: div wrapped in a jQuery object
publishState: function(name: String, value) - changes the value of a state
triggerEvent: function(name: String, callback: function(err)) - triggers an event
setHeight: function(height: Number) - sets the height in pixels and recalculates the page
data: Object containing custom data - read and write by doing instance.data.your_variable
}

3 Likes