How to pre-populate a question with a URL variable (& hide it from respondents!) | XM Community
Skip to main content
I am trying to figure out the following scenario;



I have a list of people that will be receiving a survey about their recent experience at one of several shopping properties. For most of them, we will already know which property they will be answering for, and we wish to automatically categorize that. For others we will not know, and will want to ask them.



In order to achieve this, I have set up a question that lists all of the properties and asks respondents to answer the question.



For respondents that we already know the answer, I have created a series of open links that use the Q_PopulateResponse function to populate the relevant answer. I have been able to test this successfully; it works! :)



What I have *not* been able to do is successfully create logic to hide the question from people for whom the question is not relevant, because when I use display logic to hide the question, it also seems to simultaneously cause the Q_PopulateResponse function to be ignored.



Is there any way to hide a question from respondents but still auto populate it? I am not fluent in advanced scripting but I am not oposed to using javascript if it is absolutely necessary.
What I would do in this scenario is to use an embedded data field to store the property info. You can append the value (in this case, the shopping property) to the end of a URL to the end of a URL") and then use display logic to only display the question if the value is empty.



To make your reporting easy, at the end of your survey flow, be sure to save the answer to the question as the same embedded data field. Then you won't run your analysis on the question (because some will be blank) but instead on the embedded data field, which will have a value for each response.
Thanks so much JenCX!



Sounds like I might have made things a bit too complicated for myself. My reasoning for trying to stuff all of the answers into a question was that I wasn't sure how to set up labels for reporting off of an embedded data field.



Now let's say that yours truly has run into a time crunch and cannot change the URLs without introducing some other logistical issues.



Hypothetically do you think it is still possible to use the embedded value solution you suggested if I kept the Q_Populate variable set up I originally created ( i.e. Q_PopulateResponse={"QID8":"17"} ) but then created an entirely new question to capture those I didn't have an answer for?
Hmm. Maybe? I don't THINK Q saves that variable in an extractable way but I've never tested it, either.



What you might try instead is to have the store question first in its own block and auto-advance through it with a timing question. Then later in the flow, you can use branch logic to say if the question isn't answered, show the block again.



It'll look a little messy because respondents will see it flash up for a split second before the timer moves them to the next page, but it will get all of your answers in one question.
@WilliamGibson,



If the question is not force response, you can hide it with JavaScript like this:

```

if("${e://Field/Q_PopulateResponse}".length > 0) jQuery("#"+this.questionId).hide();

```
Hi Tom! That's definitely a handy script but is there any way to make the hide function dependent on whether it's been pre-populated though? That's my challenge. :)



For now I am using the timer solution; thanks Jen!
> @WilliamGibson said:

> Hi Tom! That's definitely a handy script but is there any way to make the hide function dependent on whether it's been pre-populated though? That's my challenge. :)

>

> For now I am using the timer solution; thanks Jen!



Sure, that was the intent of checking the length of Q_PopulateResponse, but this is probably better (you should still be able to use force response):

```

var q = jQuery("#"+this.questionId);

if(q.find("input:checked").length > 0) q.hide();

```

Leave a Reply