Use results of a JS (toolbox) in further workflow steps


Is it possible to use the result of a JS code in a step of the workflow made with a toolbox in one of the next steps? For example update a database entry via “Make changes to thing” with a result of JS calculation on the previous step?

I know how to do it via Javascript-to-Bubble element, but is it possible to stay only in the backend?

KR, Dmitry

1 Like

You can you trigger Javascript to be run inside of a workflow element. If you want to keep additional elements in that workflow running, it’s fine since your javascript code is executed asynchronously ( you could insert a JS listener into an html element on the page, which would would in turn trigger another workflow when your specified condition is met). As of now, I don’t believe there is a way to use the toolbox plugin in a synchronous workflow (ex. wait for response and then continue with workflow).

A hacky solution would be to have a series of event listeners (inside of html elements in your front-end) that trigger separate workflows or store results of your javascript backend code inside of a function (i.e. Toolbox plugin’s feature to store values in a fn_). The stored value can be used to change conditions on which your desired workflow is based (i.e. each step inside of your original workflow might be set to run only when samplecondition_1=true AND samplecondition2=false). If you insert a “wait 5 seconds” delay element into your desired workflow right after you run the JS using the toolbox plugin, that would give your workflow enough time to wait until any conditions (or values) are changed by your event listeners before moving onto the next workflow item. In this sense, you could keep everything in the ‘backend’.

For example, your workflow would look something like this:

  1. Run javascript ----> calculate something in the “run javascript” element of toolbox plugin
  2. Insert a delay for X seconds (maybe 2?) element into your workflow…Meanwhile, your front-end listener (inside of an html element) stores the result of that javascript you just ran in the workflow into fn_bubbleresult1 (i.e. a toolbox plugin element you create and place into the front-end of your page)
  3. After waiting X seconds, as you have just specified, your workflow continues on to “Make changes to thing” and utilizes the value of fn_bubbleresult1, which was updated during the delay that you included in this workflow.
  4. Now, you’ve just run a single workflow with certain steps based on the result of javascript code from a previous step
1 Like

Hi supernaturally,

thanks for this detailed relply - that’s the way I do it now and it seems to be working, although not a straightforward method.

But the problem remains when I want use javascript calculations inside an “API Workflow” and return a result of calculations in a API response - i.e. use Bubble only as a backend. Now there is no front-end with “fn_bubble_…” or other elements.

Is there any way to deal with it?

KR, Dmitry

You could use a serverless endpoint on to run your javascript calculations, and loop that into your Bubble backend via the API connector.

Lots of people in this forum use Webtask to interact with javascript code via API calls from Bubble. If you want to run other languages (python, etc.), you can always use AWS Lambda, but its much more complicated to setup.

1 Like