Escape-Unescape a return URL | XM Community
Skip to main content
Hello everyone,



I am a non CS person trying to sort the following out :



- I am working with an external provider who wants me to re-route people as follow:

1) They pass the following parameter to me through the url : &return

2) this parameter is in "escaped" format, for example:



https%3A//qcsurveys.gfksay.com/mriweb/mriweb.dll%3FI.Engine%3Dengine1%26I.Project%3DS21937%26I.Session%3Did2pldaovuievnhi4a6nrai5o3gaaaaa%26I.SavePoint%3DSTATUS%26I.Renderer%3DHTMLPlayer



Qualtrics seems to have a built in functionality such that this parameter is not saved as such but is partly (? - again I am not a CS person 😀 ) "unescaped" and thus saved as such:



https://qcsurveys.gfksay.com/mriweb/mriweb.dl?I.Engine=engine1&I.Project=S21937&I.Session=id2pldaovuievnhi4a6nrai5o3gaaaaa&I.SavePoint=STATUS&I.Renderer=HTMLPlayer



Which is good in that I can directly used this saved parameter as a redirect link, but not good if I have to pass this parameter on to an external website. Indeed, when I try to do this, anything after the first & is dropped.



& appears to be "&" in html...My guess is that I need to "escape" this parameter so I can pass it on through a URL. Yet, the presence of amp; is making it not very straightforward for a non CS person like me googling this...



Anyone as a suggestion what java code I should be using?



After 4h of trying to problem solve I am starting to lose hope :neutral:



Thanks!

Charlotte
the HTML code for "&" is "&" (without double quote).

to escape "&" in URL, please refer this: https://stackoverflow.com/questions/16622504/escaping-ampersand-in-url
JavaScript to re-encode the url:

```

Qualtrics.SurveyEngine.setEmbeddedData("newurl", encodeURIComponent("${e://Field/orgurl}");

```

Then pipe ${e://Field/newurl} as the url parameter value in your redirect url.
Thanks everyone for suggesting solutions:



My post was a little confusing. Let me try one last time:



1) The url is encoded:



i.e. & are replaced by %3B



(I cannot past the encoded version as it gets "de-coded" automatically on this discussion board (I wish I had taken CS courses in undergrad!)



2) qualtrics automatically decodes it:



https://qcsurveys.gfksay.com/mriweb/mriweb.dll?I.Engine=engine1&I.Project=S21937&I.Session=1nfiu3l655iu4bza1hn52qvoqqaqaaaa&I.SavePoint=STATUS&I.Renderer=HTMLPlayer



and saves it as such. This parameter is called "return". When I download the data, in the return column, I get the above.



3) I thus need to encode it again to pass it on.

tomG suggested very helpful code.



a) I generate a new empty embedded parameter : return_url



b) and then add the following javascript code 😀



Qualtrics.SurveyEngine.addOnload(function()

{



/*Place your JavaScript here to run when the page loads*/



Qualtrics.SurveyEngine.setEmbeddedData("return_url", encodeURIComponent("${e://Field/return)"));



});





But it is not working -> it does not populate the return_url parameter. I have no clue what I am doing wrong.
@cc1933,



Define the return_url embedded data variable at the beginning of your survey flow.

!



Then after the block where your JavaScript runs, pipe it into your url:

`https://yourdomain.com/page.php?parm1=x&return=${e://Field/return_url}`
@TomG the issue is that the javacode --or something else I am not understanding-- does not "populate" return_url. Anyways. I found another solution that does not require decoding and encoding a URL. Thanks for the input though, very grateful that you took the time!
Ah, I see the problem now. It looks like you have a `)` instead of a `}` at the end of ${e://Field/return} in your JavaScript.
it works! @TomG thank you! (and my bad for not catching this).



Now that I have worked out another solution, I mostly get the intellectual satisfaction of seeing it work and you get my eternal gratitude!



(a developer told me that passing a long URL like that would not be a good idea, in his words: " if you pass in a whole long url as a parameter, the url won't work because its too long. i think this might be a big risk", I have thus defaulted to extracting the parameters from the URL and passing that along.)



[For others and future references, just adding these tags: GfK, Knowledge Panel™️]

Leave a Reply