Set Embedded Data off of portion of text response | XM Community
Skip to main content

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}

@JasonPatrie,

You can use JavaScript to split the string into 1000 character chunks and set embedded data fields for each chunk. I would do it in the addOnPageSubmit function of the text entry question. You will need to define embedded data fields for the maximum number of chunks in the survey flow prior to the block containing the text question.


 @JasonPatrie The question where you are collecting the text input from add the below JS 

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, chunksni]);
//console.log(embeddedDataFieldName + ": " + chunksni]);
}
}
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