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!