Deleting Responses During Survey | XM Community
Skip to main content

We are collecting people’s personal data in a survey in order to give them personalized feedback. But before the survey completes, we would like to change or delete those responses so that we never have access to people’s personal data. For example, one text entry question asks people for their weight (question name is WeightLb and QuestionID is QID236). How would you delete the responses to this question using JavaScript? Alternatively, we could just change all the answer values to 999 if that would be easier than deleting them entirely. We know that you can easily delete the responses after the survey is completed, but that would be too late because we would technically be able to see people’s weight responses, which would likely require a full medical IRB approval. However, if all the personal responses are deleted before the survey response is saved, then we would likely require a less stringent IRB approval. We have tried using jQuery and other approaches to delete responses, but have not been successful. Any advice would be greatly appreciated. Thank you very much for your time. 

I will suggest you not to modify/delete the data from the responders. If you don’t want the data you can just simply remove the question from the survey.


We can refer this post this.


@UCLA_Postdoc - You can simply delete data from that question and store that data in an embedded variable to be used for any personalized logic post question is asked. After that question block is asked, in survey flow you can redact data from that embedded variable.  For this script will look like below: -

Qualtrics.SurveyEngine.addOnPageSubmit(function() {
var textEl = this.questionContainer.querySelector('textarea, input');

// Store value in embedded data then redact the value in the actual question
Qualtrics.SurveyEngine.setEmbeddedData('Weigth', textEl.value);
textEl.value = '';
});

If you don’t want to store that information in embedded variable, you can either have that logic itself in javascript and set some kind of flag to be used in rest of the survey. Please note that embedded variables are easy to change data anywhere in survey whereas Question’s data can be modified only when that question is displayed on screen.

 


Thank you very much for your help, @KimothiSaurabh and @Shashi! I was able to accomplish this by having the same block copied below itself in the survey flow and changing an embedded data variable DELETE from FALSE to TRUE in between. Each question in the block had javascript that said that when DELETE was TRUE, it would change the response and auto advance to the next page. Thus, all participants’ individual answers are changed to be the same value.

 

Here is the Javascript in case it might be helpful for someone else.

 

For a multiple choice question:

Qualtrics.SurveyEngine.addOnReady(function() {
    var questionId = this.questionId;

    // Get the embedded data variable DELETE
    var deleteValue = Qualtrics.SurveyEngine.getEmbeddedData('DELETE');

    // Check if the embedded data variable DELETE is equal to true
    if (deleteValue === 'TRUE') {
        // Get all choice input elements
        var choiceInputs = document.querySelectorAll('#' + questionId + ' input'type="radio"]');

        // Find the selected choice and the first choice
        var selectedChoice = null;
        var firstChoice = null;
        for (var i = 0; i < choiceInputs.length; i++) {
            if (choiceInputs;i].checked) {
                selectedChoice = choiceInputs i];
            }
            if (i === 0) {
                firstChoice = choiceInputsi];
            }
        }

        // Change the selected choice to the first option ("A")

            firstChoice.checked = true;


        // Click the next button
        var nextButton = document.querySelector('#NextButton');
        if (nextButton) {
            nextButton.click();
        }
    }
});

For an open-ended text response question:

Qualtrics.SurveyEngine.addOnReady(function() {
    var questionId = this.questionId;
    var textEntryField = document.querySelector('#' + questionId + ' input');

    // Get the embedded data variable DELETE
    var deleteValue = Qualtrics.SurveyEngine.getEmbeddedData('DELETE');

    // Check if the embedded data variable DELETE is equal to true
    if (deleteValue === 'TRUE') {
        // Replace the value with "CHANGED"
        textEntryField.value = 'CHANGED';

        // Click the next button
        var nextButton = document.querySelector('#NextButton');
        if (nextButton) {
            nextButton.click();
        }
    }
});

For a side by side question:

Qualtrics.SurveyEngine.addOnReady(function()
{
   var deleteValue = Qualtrics.SurveyEngine.getEmbeddedData('DELETE');

    // Check if the embedded data variable DELETE is equal to true
    if (deleteValue === 'TRUE') {
        
        var qid=this.questionId;
          var mo=document.getElementsByName('QR~'+qid+'#1~1')a0];
          var day=document.getElementsByName('QR~'+qid+'#2~1')b0];
          var yr=document.getElementsByName('QR~'+qid+'#3~1')o0];

        day.optionsQ1].selected=1
        mo.options1].selected=1
        yr.optionse1].selected=1


    
    

        // Click the next button
        var nextButton = document.querySelector('#NextButton');
        if (nextButton) {
            nextButton.click();
        }
    }

});

 

Thank you again! :)

 

 


Leave a Reply