Piped text {lm://Field/x} as part of with display logic inside loop | XM Community
Solved

Piped text {lm://Field/x} as part of with display logic inside loop

  • 26 July 2022
  • 9 replies
  • 431 views

Badge

Help appreciated.
Problem statement: Using a piped reference to a {lm://Field/2} variable containing a piped reference to embedded data {e://Field/1} returns the correct value, but is not recognized in display logic to control whether question is shown.
Embedded data at runtime from cvs input:
aa=1
bb=0
cc=1
Loop matrix data:
Fld1 Fld2
aa ${e://Field/aa}
bb ${e://Field/bb}
cc ${e://Field/cc}
The embedded data holds a flag for whether the question should be shown for the current loop. If field 2 =1, do not show; if field 2 <> 1 then show the question. The correct values, 1 or 0 are being correctly loaded into {$lm://Field/2} per text displayed during the current loop, but the question is ALWAYS shown. Thus, it seems as though the display logic will not recognize ${lm://Field/2} value for control. Logic is display if <>1.
I hope this explanation is clear enough to get some guidance. Thank you in advance for reading.
Jodene

icon

Best answer by TomG 27 July 2022, 16:45

View original

9 replies

Badge

Update: I have learned from Qualtrics support that Loop/Merge does not read row-by-row and that the display logic looks for any occurrance in any row of field 4 for <>1 in this case. Thus, if any 0 occurs, all rows will be shown even if there is a 1 in Field 2 for the current iteration of the loop. I'm stumped as to how to get around this. Any ideas?

Userlevel 7
Badge +27

Use JS to copy the loop & merge field to an embedded data field, then use the embedded data field in display logic. You may need to add a text/graphic question to the beginning of the loop then use JS to click Next.

Badge

Tom, thank you so much. It'll be my first go-around with JS, never used it before. So I can make a numeric variable placeholder, say varj={$lm/field/2} that will load the current loop/merge field2 into it for each instantiation of the loop in a question just prior to the display logic. Is that the idea?
That is an idea I actually tried without JS and the embedded field came up "" because in the survey flow I could only add it prior to the block. I will try messing around with JS to do this within the block. Any words of wisdom about it?
Have a swell day!

Userlevel 7
Badge +27

https://community.qualtrics.com/XMcommunity/discussion/comment/48082#Comment_48082You can add this JS to a Text/Graphic question at the beginning of the loop, followed by a page break:
Qualtrics.SurveyEngine.addOnReady(function() {
Qualtrics.SurveyEngine.setEmbeddedData("field2","${lm://Field/2}");
this.clickNextButton();
});
Then you can use field2 in display logic on the next question.

Badge

Tom! You're the best. It works! And FYI it works best if I leave out the next click and put embed the JS in the onLoad for question that has the logic. Terrific. I so appreciate your help.

Badge +2

TomG Thanks for this brilliant solution. I adapted it a bit for my purposes so that it didn't involve a page break — I set the embedded variable I'm using in my display logic with what I need for the first loop before the loop starts (i.e., in an earlier block). Then, I add the code you suggested directly on the question in my loop so it updates before the next question.
However, when I'm trying to combine this with question randomization, the display logic isn't working and none of the questions appear anymore. As soon as I turn the randomization off, it works again. — any idea why?

Userlevel 7
Badge +27

https://community.qualtrics.com/XMcommunity/discussion/comment/55959#Comment_55959If you've randomized all the questions, then your first question might not be the first so the embedded variable won't be set before the next page. You could use advance randomization to always make the first question first, or add the JS to all the questions.

Badge +2

Hi @TomG, thanks so much for getting back to me. I am using advanced randomization to make the question first question first, which is working. Also, when I pipe the embedded variables onto the page to check that they're actually getting changed to the correct values, it is indeed working. It's just that the questions with display logic don't appear at all after the first loop. Is that clearer? Thanks!
https://community.qualtrics.com/XMcommunity/discussion/comment/56007#Comment_56007

Userlevel 7
Badge +27

https://community.qualtrics.com/XMcommunity/discussion/comment/56017#Comment_56017Since I haven't seen the survey, I'm not sure, but my guess is that since you 'set the field before the block' the first question is only being displayed in the first loop (because it has display logic based on that embedded field), and since that is where you set the embedded field for the remaining questions, none of the questions in the loop are being displayed.

Leave a Reply