How can I trim spaces from a text response? | XM Community
Solved

How can I trim spaces from a text response?

  • 27 March 2018
  • 5 replies
  • 193 views

Userlevel 1
Badge +1
I have surveys set up as scholarship applications, they include email triggers that send a recommendation request. The recommendation requests have a link to a second survey for collecting the recommendation letters. I have embedded some data in the URL (student name and email address, some other info) so that it automatically populates in the recommendation form.

The problem is that any time there is a space in the embedded data it causes the URL to not work, and come up with {"code":403,"message":"Invalid Token"} in the browser for the person who is trying to send a recommendation.

Yes, I know how to put validation on a question that can force students to not use a space, but some people have a space in their names. (Although some test have just turned out to be people who hit the spacebar before moving to the next field.)

I would like to create embedded fields that would be filled from the student's responses, but transformed to remove spaces. (Or, hypothetically any other offending character.)

Or, perhaps another, better solution would be how can I allow a space in the URLs without breaking the URL?
icon

Best answer by TomG 27 March 2018, 21:49

View original

5 replies

Userlevel 7
Badge +27
You need to urlencode your link parameters. You can do this with a web service or JavaScript.
Userlevel 1
Badge +1
Thanks @TomG - I've just skimmed the page you referenced, and although I have not had time to actually test this yet it looks like it should help me solve my problem.

I had just used piped text to create the URLs directly in the triggered emails, but it looks like I may be building the URLs in a hidden question or as embedded data which will be "urlencoded" and then pipe that into the triggered email.
Userlevel 7
Badge +27
@markmeadows,

Yes, you are headed down the right path.
> @markmeadows said:
> Thanks @TomG - I've just skimmed the page you referenced, and although I have not had time to actually test this yet it looks like it should help me solve my problem.
>
> I had just used piped text to create the URLs directly in the triggered emails, but it looks like I may be building the URLs in a hidden question or as embedded data which will be "urlencoded" and then pipe that into the triggered email.

HI @markmeadows,

I am in exactly the same position you've arrived at with this post. I'm not sure how to execute your solution though. Were you able to url encode text answers before piping them into the email trigger? If so, how?

Really hoping to follow your steps here.
Andrew
From the TobG urlencode link above, I took the code and got it working. It took me a while because it seems like most of the pages that demonstrate the Qualtrics setEmbeddedData command show (what looks like) a dot between the name of the variable and the value to which it is being set. I wouldn't work until I change it to a comma. Below, in my last line, that is ('NoSpace' comma encodedInputString);

From there, the "NoSpace" variable/embedded data can easily be piped to the email trigger (or email action).

Qualtrics.SurveyEngine.addOnReady(function()
{
var inputString="${e://Field/WithSpace}";
var encodedInputString=escape(inputString);
encodedInputString=encodedInputString.replace("+", "%2B");
encodedInputString=encodedInputString.replace("/", "%2F");
Qualtrics.SurveyEngine.setEmbeddedData('NoSpace',encodedInputString);
});

Leave a Reply