Hide not answered questions in email task with piped text | XM Community
Question

Hide not answered questions in email task with piped text

  • 1 August 2023
  • 4 replies
  • 50 views

Userlevel 6
Badge +12

Hi community! I'm setting up an email task for sharing eacht survey response results with a group of colleagues. Since I was not happy with the automated response report I made my own with piped text.

Is there is a way to hide the questions that have not been answered or did not appear due to display logic?

 

 


4 replies

Userlevel 6
Badge +18

Hi @JohannesCE,

Can you try enclosing individual variable (Steekwoord 1, 2 etc) in a <span> tag Ex.

<span id=”S1”>Steekwoord 1 : PIPE TEXT</span>

And then through JS hide the id=”S1” if QID1 does not have data i.e., empty.

Userlevel 6
Badge +12

Hi @SaurabhPujare_Ugam, great tip. However, since that's too many fields to give IDs, I decided that I'd rather have “null” appear after questions that have not been answered. So now the goal is to have appear “null” when a piped text field is empty. 

Since all piped text field start with &{ and end with }, I tried this script, but it's not working:

<div id="surveyResults">
<!-- HTML content -->
</div>

<script>
// Function to check and replace empty piped text fields with "null"
function replaceEmptyPipedFields() {
const surveyResults = document.getElementById("surveyResults");
const pipedFields = surveyResults.querySelectorAll("span[id^='${']");

pipedFields.forEach((field) => {
const text = field.innerText.trim();
if (!text) {
field.innerText = "null";
}
});
}

// Call the function to replace empty piped text fields when the page loads
replaceEmptyPipedFields();
</script>

Any idea why?

Userlevel 6
Badge +18

Hey @JohannesCE,

Could it be due to when the pipe text is parsed, there will not be any significance of “${“, thus against the span we should have the actual value of the pipe text.

Thus, would it make more sense in the code, if we directly check whether the span contains some value.

Hope I’m making any sense here :)

Userlevel 6
Badge +12

Hey @JohannesCE,

Could it be due to when the pipe text is parsed, there will not be any significance of “${“, thus against the span we should have the actual value of the pipe text.

Thus, would it make more sense in the code, if we directly check whether the span contains some value.

Hope I’m making any sense here :)

 

Yes you do! When the email template is parsed and rendered, the ${...} placeholders for piped text will be replaced with their actual values. As a result, the JavaScript code should directly check whether the span elements contain any value instead of using ${...} placeholders. This way, it will correctly detect whether the piped text fields are empty or have actual content.

I tried this, but it's still not working:

function hideEmptyElements() {
const variables = ["QID6/ChoiceTextEntryValue", "QID205/ChoiceTextEntryValue"];

variables.forEach(variable => {
const spanElement = document.getElementById(variable);
if (spanElement && !spanElement.textContent.trim()) {
spanElement.style.display = "none";
}
});
}

I'm starting to suspect Qualtrics does not allow JS at all in emails. Could this be? According to one support employee it should work, but nothing I do with JS here as any effect...

Leave a Reply