Solution found. The problem was with the line:var trials = "${e://Field/five_sampled_numbers}";trials , after the above assignment, contains a string of characters rather than an array of numbers. This means that using a function that operates on arrays would not work. The solution is to convert "${e://Field/five_sampled_numbers} to an array of numbers once its retrieved from embedded data.This solution came after someone answered my question at StackOverflow: https://stackoverflow.com/a/61985522/6105259For anyone who might be interested in this in the future, here's the code I ended up using. It works perfectly.First, in a question that comes before the Loop & Merge block, insert the following JS code:Qualtrics.SurveyEngine.addOnReady(function(){ /*Place your JavaScript here to run when the page is fully displayed*/ // the following function randomly subsets a list of numbers// inspired by: https://stackoverflow.com/a/11935263/6105259 function getRandomSubarray(arr, size) { va
rondev --Yes, I wrote my comment after testing it and witnessing that it didn't give me the desired result. But you are saying that for you it was working OK? If so, it's very strange.I will also note that I've been still trying to figure out a solution through JavaScript, and interestingly, the JavaScript code I use fails for the exact same reason as the solution you proposed: when matching ${lm://CurrentLoopNumber} to the array resulted from the 5 sampled numbers, the matching returns TRUE as long as ${lm://CurrentLoopNumber} matches ANY digit in the array of 5 sampled numbers, even if it doesn't represent a correct match. The only time it returns FALSE is when ${lm://CurrentLoopNumber} doesn't match any digit in the set whatsoever. When I tested the JS code out of Qualtrics, the matching was working fine; meaning, only proper exact matches returned TRUE. To me this just adds confusion, how could it possibly be that same JS code is behaving differently. And display logic acting
Hi rondev , Thanks for your answer. I fell in love with this solution, and I almost celebrated this, but then I realized that display logic based on contains is problematic because if five_sampled_numbers includes, for example: 11, 12, 13,14, 15, then for the display logic, loop numbers 1, 2, 3, 4, 5 satisfy the logic. 11-15 contain the digit 1, 12 contains the digit 2, 13 contains the digit 3, etc. So even though neither 1, 2, 3, 4, or 5 were part of five_sampled_numbers , loop numbers 1-5 would nevertheless be displayed because they satisfy the logic's matching criteria. Is there a way to circumvent this?Thanks,Emmanuel
Thanks TomG !
Hi PraDeepKotian_Ugam, thanks for responding. Unfortunately, what you are suggesting doesn't address my problem. I don't need to subset the total number of loop iterations, but only a specific question within the loop. The rest of the questions should be displayed in all loops.Emmanuel
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
Sorry, we're still checking this file's contents to make sure it's safe to download. Please try again in a few minutes.
Sorry, our virus scanner detected that this file isn't safe to download.