Share feedback, ideas and get community help

Updated 3 months ago

Script to process data

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'
}

Can anyone help me with this?😢
Attachment
Captura_de_Tela_36.png
1
V
J
m
25 comments
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)
You could do something like:
Attachment
image.png
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.
Example: when typing 15 characters 123456789123456 the answer would be this typed number that contains 15 characters.
if I type less than 15 characters. Example: 123456 the response would be an error message.
No momento com a sua dica ficou assim....
Era para trazer esse numero já que tem 15 digitos mas trouxe a mensagem de erro.
Attachment
Captura_de_Tela_37.png
length is lower case.
{{sus}}.toString().length == 15
Attachment
image.png
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?
You forgot to select the operator in the Condition block.
Select "Equals to".
Attachment
image.png
PERFEITO AMIGÃO
OBRIGADO PELA FORÇA, DEU CERTINHO AGORA👍 👏 🙌
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?
here is my flow
Attachment
image.png
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.
first "address" is - bwazfg9gtg0tpl3kve4sjpyt; and the scrip has -> vocfhmanv47b4shl8ejm2u7vf
I'm assuming that I'm doing something wrong, but can't figure it.
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.

For example,

"{{URL base}}/path" => vclfqgqkdf000008mh3r6xakty/path
{{URL base}} + '/path' => https://domain.com/path
${{{URL base}}}/path => https://domain.com/path
Add a reply
Sign up and join the conversation on Discord