Using data from a javascript workflow in Bubble

I am struggling with getting data generated in a javascript element into Bubble… I hope someone can help.

What I am trying to accomplish is to set the list of dates between a start and end date to a LisofDates field in Bubble. I usually do this using the List of Dates plugin but in this case, I am creating the task using a workflow so I can’t access the plugin.

Instead, I use the Run Javascript workflow element and the following Javascript:

Blockquote
const getWorkingDays = (startDate, endDate) => {
const workingDays = ;
let currentDate = new Date(startDate);
while (currentDate <= endDate) {
const day = currentDate.getDay();
if (day !== 0 && day !== 6) { // Check for weekdays (not Sunday or Saturday)
workingDays.push(currentDate.toISOString().slice(0, 10));
}
currentDate.setDate(currentDate.getDate() + 1);
}
return workingDays;
};
// Get the start and end date from inputs
const startDate = properties.param1;
const endDate = properties.param2;
// Calculate the working days
const workingDays = getWorkingDays(startDate, endDate);
// Store the working days in a custom state named “WorkingDays”
const workingDaysState = elementProperties.WorkingDays;
workingDaysState = JSON.stringify(workingDays); // Convert to JSON for safer storage

The script works fine but I don’t know how to use the result of it. The “elementProperties.WorkingDays” is not recognised.

image

So is this step that I need some advice… thanks a lot.

See this answer (the first part);

What you need is from that javascript code, you will trigger a bubble workflow with some parameters. Js2bubble element lets you create this function (a function to use in js that will trigger a bubble workflow). You have to play with passing params a little bit to understand the structure, or check toolbox plugin’s documentation.

1 Like

Thanks for this… I will mess around more with js2Bubble- I haven’t figured out how to accomplish this with that plugin yet, but as you say, maybe it is related to the params… thanks for pointing me in that direction and prompting me to take another look at that.

Here is more example for you. See the demo below. In this demo, the value is received from the input and done some modification in the JS (I append itself 3 times) and add it to the database by calling the JS2Bubble element’s provided function:
chrome_bt9Eu4iVbh

This is the js2bubble element:


When you create this element with these checkboxes and value type, the bubble_fn_create function, that accepts a text is available to call in JS.

When the button is clicked, a javascript is executed that calls this function in the previous step:

Then, finally, you will receive this event with a workflow:

If you want to check the whole editor, here it is: Test for Forum 12 | Bubble Editor

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.