Check if transaction number is already part of the data set | XM Community
Skip to main content

Hi, 

So I have a survey that will be sent every time someone buys a product. This means each customer should be able to take the survey multiple times, but I want to make sure they can only take it once per Transaction. The survey is sent through the email team with an anonymous link, and TransactionNumber is the variable passed on that I would like to use. I don’t want to store the information in the XM Directory, and I want them to be directly sent to the end of survey message if they have already taken the survey. 

So far, I have created a variable called UsedTransactionNumbers. Then, there is the introduction question/messsage, to which I added the following JavaScript code:

 

Qualtrics.SurveyEngine.addOnload(function() {
    var transactionNumber = Qualtrics.SurveyEngine.getEmbeddedData('TransactionNumber');
    var usedTransactionNumbers = Qualtrics.SurveyEngine.getEmbeddedData('UsedTransactionNumbers') || '';

    // Convert the used transaction numbers to an array
    var usedTransactionNumbersArray = usedTransactionNumbers.split(',');

});

Qualtrics.SurveyEngine.addOnUnload(function() {
    var transactionNumber = Qualtrics.SurveyEngine.getEmbeddedData('TransactionNumber');
    var usedTransactionNumbers = Qualtrics.SurveyEngine.getEmbeddedData('UsedTransactionNumbers') || '';

    // Convert the used transaction numbers to an array
    var usedTransactionNumbersArray = usedTransactionNumbers.split(',');

    // Add the new transaction number to the array if it's not already there
    if (!usedTransactionNumbersArray.includes(transactionNumber) && transactionNumber !== '') {
        usedTransactionNumbersArray.push(transactionNumber);
    }

    // Save the updated list of used transaction numbers back to embedded data
    Qualtrics.SurveyEngine.setEmbeddedData('UsedTransactionNumbers', usedTransactionNumbersArray.join(','));
});

 

 

However, this seems to not store all of the past transactions, and when I retake the survey, nothing happens. Do you have any idea of what should be done? Ideally, everytime someone takes the survey, their TransactionNumber is added to a list that is contained in and embedded data variable. So that list constantly grows. And then we would just check whether the TransactionNumber is already in that list.

 

Thank you very much!

@InsightsHodge That AI generated JavaScript code only store TransactionNumber of that session, you cannot just save used number with code. So there’s way you can prevent multiple survey submission.

Do personal link distribution linked with the transaction: Each link is unique and can only be taken once. So the respondent can still answer to the surrvey multiple time but to each transaction only once. And that the proper way of setting up survey after transaction. You can even link the transaction data to your survey data and proper survey fatigue prevention.

https://www.qualtrics.com/support/iq-directory/transactions-tab/transactions/#Distributing


Leave a Reply