Hi All. I have some large essay response fields that need to save to a panel via a workflow trigger. The embedded data fields in the panel are capped at 1024 characters and much too short. I want to generate embedded data fields in the survey that will then be saved to the panel via workflows. Is there a way to create an embedded data field set to equal the text response of a question, but ONLY capture characters 1-1000. I would then create follow-up embedded data fields set to characters 1001-2000, and so on. Here is an example of the field I am looking to take only the first 1000 characters from: ${q://QID40/ChoiceTextEntryValue}
Solved
Set Embedded Data off of portion of text response
Best answer by Deepak
Qualtrics.SurveyEngine.addOnload(function() {
var that = this;
function splitTextIntoChunks(text, chunkSize) {
var chunks = [];
for (var i = 0; i < text.length; i += chunkSize) {
chunks.push(text.substring(i, i + chunkSize));
}
return chunks;
}
function setEmbeddedDataFields(text) {
var chunks = splitTextIntoChunks(text, 1000);
for (var i = 0; i < chunks.length; i++) {
var embeddedDataFieldName = "ResponsePart" + (i + 1);
Qualtrics.SurveyEngine.setEmbeddedData(embeddedDataFieldName, chunks[i]);
//console.log(embeddedDataFieldName + ": " + chunks[i]);
}
}
var qid = this.questionId;
var textField = document.getElementById(qid).querySelector('.InputText');
textField.addEventListener('input', function() {
var textResponse = textField.value;
setEmbeddedDataFields(textResponse);
});
});
Your embedded datas will be named as
ResponsePart1
ResponsePart2
ResponsePart3 and so on these will be created automatically after every 1000 chars.
Hope it helps!
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.