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.
So is this step that I need some advice… thanks a lot.
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.
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: