Storing file as embedded data | XM Community
Skip to main content

I have built a pretty complicated form which changes hands 4-5 times depending on the flow so all the responses from the different parties involved are housed in one single survey response. I’ve built something like this before and was able to develop all the logic to complete this form. However, this time I’m trying to store the files the applicant needs to upload prior to the final approval. As with other data within the different changes in hands, each time is a retake link so I’m storing and carrying over previously submitted data as Embedded Data.

 

I’ve reached out to Qualtrics Support and they’re looking at it internally, but I wasn’t sure if anyone else has experienced this and found a solution or workaround.

 

So what I think the problem is, is that when I go to upload a document and it’s stored at the question level, it stores Id, Name, Size and Type. 


But when I’m trying to store that as Embedded Data to carry forward to the next review step to be completed by another person (the one who needs to review those documents), I only have the Piped text options from that survey question of Question Text, File Size, File URL and File Name. I feel like if I was able to pipe in the Id things should work just fine but that’s not an option and I’m not entirely sure why if it’s something that’s being stored with the question. 

 

When I click on the link in the Id when it’s stored immediately from the question (first screenshot), it downloads just fine. But because I’m generating retake links for each “section” of my survey for different folks to add to the initial response, I need to store it as embedded data so it carries forward to the next section where those documents will be reviewed. And when I try to access via the File URL that’s stored in the Embedded Data that’s where I’m getting the Forbidden page.

 

My response back from Qualtrics Support was that what I was trying to achieve can’t be done. So I found a stackoverflow suggestion but I’m struggling to understand how to implement it.
https://stackoverflow.com/questions/39524925/in-a-file-upload-q-in-qualtrics-how-can-i-save-file-id-into-embedded-data

I don’t exactly understand where I’m supposed to be defining the initial variables, is it in the Survey logic or as var in Javascript? Then I don’t know what exactly needs to be in the Javascript after the file upload questions and what embedded data blocks I need where in the Survey logic.


@courtrc,

I happen to be the person that posted that. It would be JavaScript in a subsequent question. You would need to add FileID as an embedded data field in the survey flow prior to the block with the JS that sets the value. (e.g., the beginning of the survey flow).

The full JS would be (change QID1 to the appropriate QID):

Qualtris.SurveyEngine.addOnload(function() {
var fileURL = "${q://QID1/UploadedFileLink}";
var fileID = fileURL.substring(fileURL.lastIndexOf('/') + 1);
Qualtrics.SurveyEngine.setEmbeddedData('FileID', fileID);
});

 


 

Hi @TomG. Well lucky me! So I tried implementing it a few different ways trying to interpret from the stackoverflow and it didn’t seem to be correct. This is how I have it set up now and it’s still not working so would appreciate your guidance.

 

I have a few blocks that make up this section. An Intro block, the Document Submission block is where my file upload questions are and then a Agree & Submit block.

The FileID variable needs to be defined before that as embedded data before the JS which I put at the top of the survey flow.

I’ve added the JS to question 59 in the Agree & Submit block, thinking it needed to be after the file upload questions themselves in order to correctly capture the fileURL variable from the piped text. I also included a test in question 60 to see if the embedded data is getting stored, but not sure if it would populate at that point or not.

 

But the data still doesn’t seem to be recording. So I’m curious where my setup is incorrect.

 

I will have up to 3 different file upload questions in the same block, so once I figure it out for one, I can tweak variable and embedded data names to differentiate.


@courtrc - Are you using Simple layout on your survey? That changes things a bit. You would need to use setJSEmbeddedData and the embedded data fields would be __js_FileID and __js_FileURL. 


@TomG Aha, yes I am indeed using Simple layout. I forget that that layout requires slightly different things.

 

So I believe I made the changes in the appropriate places and just tested it again and still the data is not being stored. So not sure what’s going on now.

 


The JS should be:

Qualtris.SurveyEngine.addOnload(function() {
var fileURL = "${q://QID128/UploadedFileLink}";
var fileID = fileURL.substring(fileURL.lastIndexOf('/') + 1);
Qualtrics.SurveyEngine.setJSEmbeddedData('FileID', fileID);
Qualtrics.SurveyEngine.setJSEmbeddedData('FileURL', fileURL);
});

 


@TomG Hoooraay! Yes that worked.

However, after the first attempt I can’t get it to store anymore in new response records. Any idea what might be causing that?

 


However, after the first attempt I can’t get it to store anymore in new response records. Any idea what might be causing that?

My only guess is that the response were it worked was a preview and you never published the survey.


However, after the first attempt I can’t get it to store anymore in new response records. Any idea what might be causing that?

My only guess is that the response were it worked was a preview and you never published the survey.

I was publishing the survey every time then I checked my work and the JS like 12 times. I even tried to duplicate the test form again and try starting over. I even pulled up the Chrome Dev tool and I noticed there was an error saying it couldn’t find “Qualtris” so I looked back at the code you’d shared that I was copying and pasting and the very first instance of Qualtrics was misspelled “Qualtris”. But even after I fixed that I felt like even then it wasn’t working. BUT now it is. I tried it 3 times just to be safe.

Thank you so much @TomG I couldn’t have gotten here without you!


For simplicity, recapping what I ended up with that is working in the Simple layout:

  1. Naming the embedded data using the following naming convention: “__js_” + variable name. Mine was __js_FileID in the embedded data block within the Survey flow.
    I will replicate this naming convention but tweak the names for the 3 different files I need to store the ID for.
    Ex: __js_InvoiceFileID, __js_RegistrationFileID, __js_PaymentFileID
  1. My file upload questions live in the Document Submission block, so I included the following JavaScript in the first question of the Agree & Submit block, the first subsequent question after the file(s) have been uploaded.
Qualtrics.SurveyEngine.addOnload(function() {
var fileURL = "${q://QID128/UploadedFileLink}";
var fileID = fileURL.substring(fileURL.lastIndexOf('/') + 1);
Qualtrics.SurveyEngine.setJSEmbeddedData('FileID', fileID);
Qualtrics.SurveyEngine.setJSEmbeddedData('FileURL', fileURL);
});

 

  1. This gave me the desired result of obtaining the File ID substring from the File URL.
    While I didn’t necessarily need to store the File URL (so mentions of that in the code and Embedded data aren’t required), I was using it to ensure the File ID was correct.

 


Leave a Reply