Uploading data from a CSV file in a question's piped text | XM Community
Skip to main content

Hello!

 

The title of this is the general idea of what I want to do, but I understand that it isn’t very simple in Qualtrics. I have a 2x80 data set for rainfall levels by province in a country. The data set is a CSV organized by province name and a rainfall amount as a number. In the survey, respondents enter their province from a drop down list. Is it possible to have a question display the rainfall amount corresponding to the entered province without me having to enter the data by hand? 

Hi 

You can create the columns from the CSV file as embedded data in the survey flow in one SDS and later use API to send the data to the actual survey project and use the embedded data as pipe in in the questions.


Hello @krbhavya! Thanks for the reply. I’m not sure I exactly understand. You mean I can create embedded data in one supplemental data source than connect that SDS to the survey as embedded data? If yes, how can I do this exactly. 


Hi,

Yes let me tell you what I  am doing in my project is

1)upload the CSV file having data in one SDS 

2) Create Embedded data for all the columns

3) Created a workflow and call an API to transfer required columns from SDS to the survey project where I have all the questions defined 

4) then use the column as pipe in in the survey questions.

 

Hope this resolves

 


If I understand the question correctly, another approach you could take would be to use a Drilldown question type with 2 levels, hide the 2nd dropdown, and then add JavaScript to the question that will automatically select the top answer in the 2nd dropdown when a selection is made in the 1st. This will give you the province's corresponding rain amount for use in piping.

To give it a try, first create a CSV that has 2 columns: Province and Rainfall.

Then, create a Drilldown question and set the number of choices to 2. Click to add answers and then upload the CSV file to the question.

Next, add the below to the question's JavaScript in the OnReady section so that the 2nd dropdown automatically selects its 1st option when a selection is made in the 1st dropdown:

var qid = this.questionId;
var sel1 = document.getElementById('QR~'+qid+'~1');
var sel2 = document.getElementById('QR~'+qid+'~2');

jQuery(sel1).on('change', function() {
sel2.options[1].selected = true;
});

Finally, add the below CSS to the Style section of the Look & Feel so that the 2nd dropdown is not displayed to the respondent.

div.Inner.BorderColor.DL > div > fieldset > div > table > tbody > tr:nth-child(2) {
display: none;
}

Later in the survey, you can pipe in the 2nd dropdown selection/Rainfall amount by using the below, updating for your QID:

${q://QID1/ChoiceGroup/SelectedAnswers/2}

 


Thanls @Tom_1842 , this seems like a very elegant solution! Thank you!


Hi @Tom_1842 ! Sorry to call this back again. What would I have to do to have the first option (Province) randomly on page load? This is for another, similar, problem. 


Hi @adij , try using the below. It uses math.random to set var n to a random integer between 1 and 80, and then n becomes the selected option for the first drilldown row. After a half second delay, the top option in the second drilldown row gets selected.

var qid = this.questionId;
var sel1 = document.getElementById('QR~'+qid+'~1');
var sel2 = document.getElementById('QR~'+qid+'~2');

function getRndInteger(min, max) {
return Math.floor(Math.random() * (max - min + 1) ) + min;
}

var n = getRndInteger(1,80)

sel1.optionssn].selected = true;

setTimeout(function () {
sel2.optionss1].selected = true;
},500);

 


If I understand the question correctly, another approach you could take would be to use a Drilldown question type with 2 levels, hide the 2nd dropdown, and then add JavaScript to the question that will automatically select the top answer in the 2nd dropdown when a selection is made in the 1st. This will give you the province's corresponding rain amount for use in piping.

To give it a try, first create a CSV that has 2 columns: Province and Rainfall.

Then, create a Drilldown question and set the number of choices to 2. Click to add answers and then upload the CSV file to the question.

Next, add the below to the question's JavaScript in the OnReady section so that the 2nd dropdown automatically selects its 1st option when a selection is made in the 1st dropdown:

var qid = this.questionId;
var sel1 = document.getElementById('QR~'+qid+'~1');
var sel2 = document.getElementById('QR~'+qid+'~2');

jQuery(sel1).on('change', function() {
sel2.options[1].selected = true;
});

Finally, add the below CSS to the Style section of the Look & Feel so that the 2nd dropdown is not displayed to the respondent.

div.Inner.BorderColor.DL > div > fieldset > div > table > tbody > tr:nth-child(2) {
display: none;
}

Later in the survey, you can pipe in the 2nd dropdown selection/Rainfall amount by using the below, updating for your QID:

${q://QID1/ChoiceGroup/SelectedAnswers/2}

 

I am not sure what I might be doing wrong, but the drill down does not select sel2 variable. Is there somthing I am missing?


@behravesh Are you using Simple layout maybe? The above will only work for Classic, Flat, and Modern layouts.


Leave a Reply