Referencing a previous question within a ‘Loop & Merge’ block | XM Community
Solved

Referencing a previous question within a ‘Loop & Merge’ block

  • 13 March 2024
  • 4 replies
  • 34 views

Badge +3

Hello,

I was hoping that I could get some help modifying some JS, so that it can work within a ‘Loop & Merge’ block.

The script below works for a standard question, where the response from QID1 is used to determine which options will be hidden.

I am now wanting to embed these two questions within a looped block (i.e. using ‘Loop & Merge’), but have run into the problem where the initial reference to the selection from QID1 is no longer working, as there is now a loop count being applied to the question ID. Accordingly, I need to find a way to append the loop number to the reference of QID1, so that this code always applies to the question that directly preceded it (i.e. the one that is in the same loop).

 

Qualtrics.SurveyEngine.addOnload(function() {

var x = "${q://QID1/ChoiceGroup/SelectedChoices}";

if (x === "Brand1") {jQuery("#" + this.questionId + "input[choiceid='3']").closest("li").hide();}
else if (x === "Brand2") {jQuery("#" + this.questionId + "input[choiceid='6']").closest("li").hide();}

});

I am thinking that I need to apply "${lm://CurrentLoopNumber}" somewhere in the ‘var x = "${q://QID1/ChoiceGroup/SelectedChoices}"’ working, but I don’t know what the right syntax would be to achieve this. Can anyone assist?

icon

Best answer by Shashi 13 March 2024, 10:29

View original

4 replies

Userlevel 6
Badge +27

When piping the value in x you can get the piping for current loop.

Badge +3

When piping the value in x you can get the piping for current loop.

Hi Shashi,

I’m sorry, but I didn’t understand your comment. How do I link in the current loop number to the existing piping for x?

 

I’m thinking it would be something like…

  • var x = "${q://QID1 + CurrentLoopNumber/ChoiceGroup/SelectedChoices}";

...but I don’t know the correct way to write this.

Userlevel 6
Badge +27

Assuming we want to pipe in the selected choice of a current loop question which is part of loop and merge block, we can pipe in the current loop selection choice by following piping path below:

 

Badge +3

Hi Shashi,

 

Thanks for clarifying.

That is a useful trick, for getting the reference name - much appreciated.

Leave a Reply