Is it possible to load a .csv file in Qualtrics and pipe text from that file? | XM Community
Skip to main content

Hello! I am creating a survey in which participants have to write a short text based on a given prompt.

I have a .csv file with 1000 prompts. 

I would like to load this .csv file in my Qualtrics Survey and randomly pick one prompt to show to my participants using piped text.

 

The outcome should be like this:

#Text/Enty type question#
WRITE YOUR TEXT HERE BASED ON THE FOLLOWING PROMPT:

@piped_text_from_csv

 

Is this possible? Any suggestion? 

I didnt try the exact solution but can be done with something similar below.

 

Create a google sheet doc

 

 

There should be 2 blocks.

 

Your prompt question should be in 2nd block

 

 

Add these 2 embedded data after the first block.

 

 

add the below javascript to generate random number and store in the random number varialbe 

 

Qualtrics.SurveyEngine.addOnload(function() {
// Generate a random number between 1 and 20
var randomNumber = Math.floor(Math.random() * 20) + 1;

// Set the value of the variable named 'randomnumber' to the generated random number
Qualtrics.SurveyEngine.setEmbeddedData('RandomNumber', randomNumber);
});



 

 

Go to workflow and create this flow

 

In google sheet task set it as below

 

 

 

in the code task replace the existing code with this.

 

function codeTask() {
// Access the data retrieved from the Google Sheet task in Qualtrics
var googleSheetData = Qualtrics.SurveyEngine.getEmbeddedData('GoogleSheetData');

// Extract the specific value from the Google Sheet data (assuming it's in the first row, first column)
var value = googleSheetData=0]o0];

// Set the value to the embedded variable "abcd"
Qualtrics.SurveyEngine.setEmbeddedData('PipedPromptCSV', value);

// Log the result for debugging purposes
console.log('Value retrieved from Google Sheet and stored in embedded variable abcd:', value);

return {
result: ""
}
}

 

 


@praveengeorgeix Thank you for your reply.

This is exactly what I was searching for. However, after replicating the procedure by following your instructions, I ended up not showing any piped text from the .csv file, as in the screenshot here.

Do you have any suggestions for why it’s not working? 

Few questions:

-the first Java script to generate random numbers should be in the same block of the picture below, right?

-also, do I need to customize the second javascript in any way, e.g., modifying this part of the code by adding the specific name of the google sheet file? 

var googleSheetData = Qualtrics.SurveyEngine.getEmbeddedData('GoogleSheetData');

 

Thank you for your time!


I was also stuck in that way. Logically it should work. I tried few times after replying to you. Im wondering whether the issue is because of the time taken to draw information from google sheet.

But checking at the embedded data its not populated. Random number is generated anyway.

it would be best to put random nuber generator code in the 1st block with q1 to execute first.

 

Dis you try replacing the script 

var googleSheetData = Qualtrics.SurveyEngine.getEmbeddedData('PipedPromptCSV');

 

Im stuck here.


The survey response events works only when the response is recorded not when response is in progress. Secondly in code task of workflow we cannot use Qualtrics question API.

 

Another approach would be to use imported data project and it’s API to get random prompt in the survey flow. 


@Shashi Thank you for your clarification. Could you please specify better which steps should I follow to perform this? 

“use imported data project and it’s API to get random prompt in the survey flow.”

Thank you in advance


@Shashi thats new information and makes sense. As you mentioned its best to use imported data project. Didnt think about that. Thank you


@Shashi Thank you for your clarification. Could you please specify better which steps should I follow to perform this? 

“use imported data project and it’s API to get random prompt in the survey flow.”

Thank you in advance

  1. Create IDP with two columns id and prompt
  2. Upload the data in the IDP project
  3. Assign a random number to ‘RandomNumber’ embedded data using random number generator in survey flow
  4. Use web service to use this API to get prompt from IDP with generated random number.
  5. Store the response from API in an embedded data to use it in questions.

Leave a Reply