Set a variable with javascript editor

Hi,

I’m looking for a way to set variable value via a javascript code.

Let’s say I have a variable created in weweb called random_number

Then in my workflow, I add an action step (Javascript code) :

const random_number = Math.floor(Math.random() * 100) + 1;

What I want is to change the value of the weweb variable random_number by the number generated via the script.

Any idea on how to achieve this ?

I tried to add the weweb syntax in the javascript code
variables[/* random_number */'db077cca-f3d2-49ec-9962-cdea549740b9']
but it doesn’t work.

Many thanks

You can do this using a set variable step in a workflow (just go to JavaScript mode and return the intended variable value) or use the wwLib object from outside that context. I made a YouTube about setting a weweb state variable from JavaScript land.

1 Like