I'm trying to build a script without success which validates or not the number of characters to be typed. Example: the "sus" variable is where numeric data will be captured, such data must contain exactly 15 characters. After the data capture block, I added the "Set variable" block and inserted the JS there and it didn't work, I also tried using the script block and it didn't work either. Here's the script I'm using...
// This code must be placed inside the "Script" block in Typebot if (sus.length === 15) { SusTratado = sus; // Armazena o número do cartão SUS na variável 'SusTratado' } else { SusTratado = "Sus Inválido"; // Armazena a mensagem "Sus Inválido" na variável 'SusTratado' }
There's a lot of errors there: 1) You should access variables using {{variable}} 2) susis a number, so it has no length 3) The script block don't define variables (the set variable one does)
Well, if I define the maximum and minimum in the number block, the flow would only progress if I typed exactly the number "15". That's not what I want.
I want the following: Only bring the information saved in the variable {{sus}} if it contains 15 characters, that is, 15 numbers. If the person types more than 15 numbers or less than 15 numbers, it will display an Error message.
You got it my friend, but mine continues to lead to errors. Are you using the "set variable" block? Can you provide an image of how you are doing friend?
Hi, I have a similar problem. I'm trying to change the value of a defined variable using a script. But this changed value is not possible to use out of the script, in the next flow step. Any idea why?
Not working. Variable G1 is set and has value before the script. This code can change the original value, but leaving the script, value is not changed and the next flow step is still with the original value. The script is using different "pointer", I don't know why.
Variables in script are not parsed, they are evaluated. So it should be treated as if it were real Javascript variables.
So, if you write "{{My variable}}", it will parse the variable ID (something like vclfqgqkdf000008mh3r6xakty). You need to remove the double quotes to properly get the variable content value.