How to use a variable in Javascript API call

I’m trying to modify the map component so that I can pass in a default map location and then when the map bounds change, i expose those box coordinates and then re-trigger the API with the new coordinates (to obtain markers in the new location).

It works when I pass in the values of the coordinates but I tried setting up a variable but using variables[‘UID’] doesn’t pass into the javascript for the database call.

I think i have the component working properly but when I move, the map goes back to the default location set by the initial API call. I guess maybe a workaround is the initial API call with the static values, and then with the On Bounds Change event I expose, I use custom javascript to send another API call and that should allow variables , but I think that won’t work since the first API call will always re-run. Happy to hear suggestions



I think variables is defined only when you bind values in elements or actions. It looks like it’s not defined in the collection setup.

If you need to access it, they are available through wwLib, but this is a hack and may change in the future.
wwLib.globalVariables.customCodeVariables

Variables is indeed pass as a context in some places, and seems not pass here.

I take note to that, i will talk with the product team and come back to you with a more futur proof solution :slight_smile:

There is a variable that I need to use in custom javascript that is created created in the built-in functionality of weweb. When I try to insert custom code in an action with javascript and try to insert my variable, it is inserted as “variables[/* VariableName */‘31426b48-4a32-4925-8bb2-a23027426dd6’]” into the code editor. Is this the expected behavior. Is there a simple way to echo or display this variable’s value in the editor to doublecheck it’s working as I expect it to?

You can check the value of all your variables in the editor. If the js is in a bound visual element, it you can log the value to the console after calling it and storing it to a local variable or calling it directly in console.log()

If it’s a workflow, it’s a bit more of a pain in the ass but again you can view its value in the editor. After a while you’ll trust that it’s accurately displaying variable values.