Different completion url

Hello

Now that I have figured out where to specify the completion url in a survey1 - experiment -survey2 flow, I need to figure out how and where define a dynamic completion url.

Participants are asked in survey2 whether they want credit or not. If they want credit, they should be redirect to a differerent website. If they don’t want credit, their study should just end there. I have figure that I the complete/incomplete url are set up at the begin of the experiment and that thery can be changed with

psychoJS.setRedirectUrls(myCompletedURL, myCancelledURL)

My question where and how do I specify the completionURL for the yes-answers? I know the value in survey2. So it should be something along the following pseudo-code

If credit.wanted = True
then completion.url = mycompletionurl
else
then completion.url = “”

Thanks in advance for any hints.

Best wishes Jens

That’s basically it.

You need to have something in the completed URL field in Experiment Settings

Then set the actual URL in code. If they don’t want credit you could send them to your institutional homepage or something if you get an issue with resetting it to blank.

Hello

But how do I do set the url in a survey? I can evaluate the variable under Logic and then set the url via action - run expression?

Best wishes Jens

Is it an embedded survey?
Is the URL based on a response in the survey?

If the answer is yes to both then I would extract the survey responses using surveyRoutineName.getResponse() and then use a PsychoPy code component as you would for a normal experiment.

Hello

Yes, it is an embedded survey and the url is based on the response in the survey.

So, I add a routine following the survey, retrieve the value and set the code. I’ll give it a try. How do I refer to the survey response?

Best wishes Jens

Survey Test code | try it | discussion thread

Surveys can be selected using the Survey ID (so they always run the latest version) of Survey Model File (so they are protected from changes to the online version). The results of each survey are saved to the PsychoPy data file. However, if you want to access the data during your experiment you should use code of the form surveyResponse = surveyComponentName.getResponse() which copies the data into a dictionary.
In this demo I check whether four consent items have been ticked using if len(surveyResponse['consent']) == 4: and then present the second GAD-7 score on screen using surveyResponse['OHQmean']. The order of presentation is counterbalanced using the shelf, in blocks of 20 participants.

Hello

I seem to have a stupid error. I can not find the proper survey. The survey is called FrageCESD_R.

I try to access the response to the a true/false question called VPStunden.

surveyResponse =  FrageCESD_R.getResponse()
if surveyResponse['VPStunden'] == TRUE:
    psychoJS.setRedirectUrls("https://formr.uni-muenster.de/VPStunde?exp=Lexikale%20Entscheidung%20CESD-R&code=VP-Code", "https://www.uni-muenster.de/Psychologie/")
else:
    psychoJS.setRedirectUrls("https://www.uni-muenster.de/Psychologie/", "https://www.uni-muenster.de/Psychologie/")

However, I keep getting the error message that FrageCESD_R not found. Any idea why?

Best wishes Jens

Is FrageCESD_R the name of your survey routine?

Hello

FrageCESD_R is the name of the survey routine and the name of the survey itself. Name conflict? I tried various name combinations but without success so far.

Best wishes Jens

What tab are you using for getResponse?

Hello

The code component is in the Begin Routine. Somehow I got rid of the error message. So the survey is found, but the if-else construction always evaluates to false.

Begin Routine

surveyResponse = FrageCESD_R.getResponse();
if ((surveyResponse["VPStunden"] === "TRUE")) {
    psychoJS.setRedirectUrls("https://formr.uni-muenster.de/VPStunde?exp=WebpageToGoTo&code=VP-Code", "https://www.uni-muenster.de/Psychologie/");
} else {
    psychoJS.setRedirectUrls("https://www.uni-muenster.de/Psychologie/", "https://www.uni-muenster.de/Psychologie/");
}

Best wishes Jens

I think you’ll find that the block name has been pre-pended. Try print surveyResponse to check the contents and adjust the second line to suit.

Hello

I found my mistake. In the call to get a survey response you need to use the name of the routine you use to call the survey, e.g.

surveyResponse = YourRoutineName.getResponse();

I thought that this refers to the survey.

Best wishes Jens