You'll have to change %0D%0A to
using JavaScript.
https://www.qualtrics.com/community/discussion/comment/30362#Comment_30362TomG
Thanks! I see a lot of your answers on here.
I am still getting something wrong (I dont know javascript). Can I ask you for one more answer? I'm not proficient in js so I am really not sure why the following code is not working. Any ideas?
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
var add_newline = "${e://Field/links}";
add_newline.val(add_newline.val().replace(/%0D%0A/gi, "
"));
My embedded data field looks like this:
links=SAMPLE_LINK1%0D%0ASAMPLE_LINK2
My guess is that I am not sending the substituted value back to my survey anywhere so I am not really setting it to be printed, right?
Your guess is correct. add_newline is a variable. .val() is only for input elements. You could do this:
Qualtrics.SurveyEngine.addOnload(function() {
var links = "${e://Field/links}";
Qualtrics.SurveyEngine.setEmbeddedData("links",links.replace(/%0D%0A/gi,"
"));
});
Sorry TomG
I tried adding the snippet on your response to a previous question, then a page break, and then pipe my text since I know you said before you should not set embedded data values on the same question where you pipe them to:
https://www.qualtrics.com/community/discussion/5171/setembeddeddata-not-writing-back-to-qualtrics
However the piped text
${e://Field/links}
still shows no changes after the replacement.
I also tried setting the value directly to the survey flow on an embedded data block but it didn't work:
I tried:
links2 = $e{ e://Field/links links.replace(/%0D%0A/gi,"
")}
And also a test:
links2 = Qualtrics.SurveyEngine.setEmbeddedData("links2", "
Test");
and changed my piped text to
${e://Field/links2}
But had no results with either method.
Update:
Passing newline characters to a piped text in Qualtrics works using Q_EED, but you need two things:
You must use the
- tag as TomG indicated (but no need of JS magic if you use Q_EED - I could never get it working with JS).
You must add a space between the beginning and the end of the tag `
- ` for it to work correctly.
If you need more help refer to the documentation here:
https://www.qualtrics.com/support/survey-platform/survey-module/survey-flow/standard-elements/passing-information-through-query-strings/If you need some help with base64 encoding, you can use my Python script below:
# Usage:
# python3 codeb64.py
# or:
# import codeb64
# Damian Romero, University of Arizona Libraries
# Fall 2020
# CC0
import base64
import argparse
import re
class converter():
"""
Purpose:
A coder/decoder of base64
Parameters:
normal_str: A string to encode or decode
"""
def __init__ (self):
self.lstr = """
********** Working **********
"""
def mssg(self):
print(self.lstr)
def decode (self,normal_str):
secret = base64.b64decode(normal_str)
print(secret.decode("utf-8"))
def encode (self,encoded_str):
bys = bytes(encoded_str, 'utf-8')
secret = base64.b64encode(bys)
print(secret)
return secret
# You can pass '\\n's with your string and convert them to '
'
# This is useful for instance when using Qualtrisc Q_EED
def encode_with_newline (self,encoded_str):
newline_str = re.sub('\\n', '
', encoded_str)
secret = self.encode(newline_str)
print(secret)
return secret
def main():
cvtr = converter()
cvtr.mssg()
# "This is a test string"
str1=cvtr.encode("This is a test string")
# str1 = b'VGhpcyBpcyBhIHRlc3Qgc3RyaW5n'
# ("""This is a test string
# ... with new line characters
# ... """)
str2=cvtr.encode("""This is a test string
new line] with new line characters
gnew line] """)
# str2 = b'VGhpcyBpcyBhIHRlc3Qgc3RyaW5nCndpdGggbmV3IGxpbmUgY2hhcmFjdGVycwo='
samples = dstr1,str2,]
for message in samples:
cvtr.decode(message)
str3 = 'this is a line with \\n newline escaped \\n characters'
encoded_str3 = cvtr.encode_with_newline(str3)
cvtr.decode(encoded_str3)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=
'Usage = python3 codeb64.py')
parser.parse_args()
main()