Share feedback, ideas and get community help

Updated 3 months ago

setVariables not working on server script block. Am I doing missing something?

Hey guys, I'm playing around with a simple chat group trying to use the setVariable function inside a script block however no matter how I try it (single quote, double quotes, using the evaluation form {{variable_name}} ), the variable value never get updated. Can someone spot what I'm doing wrong?
Attachments
image.png
image.png
image.png
W
e
m
14 comments
this should be cool - guess you have put in 0 (zero) instead of o (small o)
Attachment
image.png
working version, please check
@William thanks for the help! I think the example I posted didn't properly demonstrated the issue. The problem is that calling setVariable inside scriptBlock is not actually setting the value for the variable {{COOL_NAME}}, as we can see from the console.log on this two line code.

COOL_NAME was initialized using a setVariableBlock with the value not cool and then the scriptBlock was exectued with the two line code, where the setVariable Function inside the script should change COOL_NAME value to some value but when I print it out using the console.log function the variable still holds it's initial value. The scriptBlock Execute on Client? is set to false as required so I'm guessing I'm missing something else. Is there any compiling flag or env variable I should set to have it working?
Attachments
image.png
image.png
SetVariable('varName','value')
Working fine to me
In block script server side
Hi @moscabuilder thanks for the inputs, but I'm afraid my issue is not related to the flow's logic. The decision block I was using was just a way to verify and ilustrate what is happening among with the server side log output. To demonstrate it I replaced the previous bot with a new one using thow blocks in a single group: a setVariable block that initializes a new variable named My Variable (freshly created, I deleted all previous variables to be sure nothing is being re-used ) followed by a second scriptBlock (server side executed) that only calls the setVariable function with a new value plus some logging.

You can see on the third image (the one showing the NextJS server side logs) that the My Variable value is never updated.

I assume that setVariables function do work on most environments, probably in all environments except my local laptop, which is why I think that I'm missing some setup step or something else.

I'm running typebot with docker using the command line docker-compose -f docker-compose.dev.yml -f docker-compose.yml up from a pristine clone of typebot repository with no modifications at all.

Peeking into the source code (disclaimer: I'm not fully familiarized with it yet) I cant see any reason that could be preventing it to work as expected on my local computer. I looked the executeScript exported function at /home/epc/Projects/typebot.io/packages/deprecated/bot-engine/src/features/blocks/logic/script/executeScript.ts

Again, thanks for giving it a shot, but I'm going crazy with this error. It does not make sense to me, what could be preventing the update? Could it be the case that the call to setVariable function is expanding/resolving to the wrong internal variable name (on my machine)? Has anyone faced something similar? @Baptiste any ideas on what I could look into?
Attachments
image.png
image.png
image.png
I used this case update the same variable several time and working fime.

Try to set My Variable = 'My Inicial value' in this way. {{MyVariable}}='Inicial value'

If not.. create a variable MyVariable using a create variable button. Is the button with the man symbol . Then assign the value of you what
I tested here and working fine
this other way too
Attachments
image.png
image.png
@moscabuilder I think I got it. I' was using console.log function inside the scriptBlock to trace the variable's current value during the script execution but it seems that setVariable updates the value only after the execution ends, therefore the printed logs output still shows the initial values given me the impression that it was not working. Once I wrote a flow similar to yours and displayed the variable in a text buble I could confirm that the value is actually being updated.
  • Lesson learned: if my script function relies on updated values during its execution I need to declare a local variable and use it instead.
Thanks for helping me with this issue!
Add a reply
Sign up and join the conversation on Discord