Share feedback, ideas and get community help

Updated last month

How to copy to clipboard with Script block ?

At a glance

A community member shared JavaScript code for copying a variable's value to the clipboard, but encountered an issue where it was copying the block ID instead of the actual value.

Another community member explained that variables in scripts are evaluated rather than parsed, and provided the solution: when using variables like {{My variable}}, they should be used without quotes to get the actual content instead of the variable ID. They demonstrated this with examples showing incorrect usage ("{{URL base}}/path") and correct usage ({{URL base}} + '/path' or ${{{URL base}}}/path). The solution was to modify the code from var valor = '{{code}}' to var valor = {{code}}.

Useful resources
Hi, I need create a function to copy into clipboard the value of a variable.

But is copying the ID of the block

Here is the JSCODE

// The value to be copied var valor = '{{code}}'; // Creates a temporary element to copy the value var tempInput = document.createElement('input'); tempInput.value = valor; document.body.appendChild(tempInput); // Select and copy the value tempInput.select(); document.execCommand('copy'); // Remove the temporary element document.body.removeChild(tempInput); // Displays the message "Copied!" alert('Copiado!');
Attachments
image.png
image.png
image.png
Marked as solution
https://community.typebot.io/use-a-variable-into-a-jscode-setvariable-block-Lpt9Ctpyf7pM#c330e80f-3531-46b0-aa29-1792183c4a36

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

So I change the code var valor = '{{code}}'; to var valor = {{code}};
View full solution
m
1 comment
https://community.typebot.io/use-a-variable-into-a-jscode-setvariable-block-Lpt9Ctpyf7pM#c330e80f-3531-46b0-aa29-1792183c4a36

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

So I change the code var valor = '{{code}}'; to var valor = {{code}};
Add a reply
Sign up and join the conversation on Discord