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

Set Embedded Data off of portion of text response


Forum|alt.badge.img

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}

Best answer by Deepak

 @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, 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!

View original

2 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5911 replies
  • May 17, 2024

@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.


Deepak
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+44
  • 1549 replies
  • Answer
  • May 17, 2024

 @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, 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