Rank-Order Carry Forward using Embedded Data | XM Community
Solved

Rank-Order Carry Forward using Embedded Data

  • 27 January 2021
  • 6 replies
  • 329 views

Badge

I am designing a survey where respondents identify the sports they played in Q8, Rank them in Q9 (using carry-forward), and then I want to embed the rank #1 in a series of questions, and then repeat those questions for sport rank #2 and #3.
Q8: Participants indicate number of years they played in sports (if at all) from a list of 17 different sports.
Q9: Uses carry-forward items of chosen responses and ask participants to rank the sports in order of importance with most important sport ranked #1. [note it will only display the sports they chose from Q8 given the carry-forward]
Q13: "How old were you when you began to play [sport ranked #1 from Q9]"
Q30: "How old were you when you began to play [sport ranked #2 from Q9]"
Q50: "How old were you when you began to play [sport ranked #3 from Q9]"

I know I cannot use piped text because I need more than the highest value and lowest value. I only care about the top 3 ranked sports from Q9 for later use throughout the survey. Some of the research I've been able to do has mentioned using JavaScript and Embedded Data https://kurtm1.sg-host.com/rank-order-carry-forward-in-qualtrics-with-javascript-2/.

This was my attempt at the JavaScript.
Do I need to include the entry value for all possible sports in the array? Or just the first 3? I also noticed that if I need to include all 17 possible entry values, that I cannot use the choice.sort() command. The only other thing I will say is that it is highly unlikely that anyone will select more than 5 sports, let alone 9 sports, from the 17 they are shown and asked about.
Screen Shot 2021-01-26 at 11.42.17 PM.png
This is my attempt at adding embedded data variables but I wasn't sure if I needed to set a value or it that would be automatically set by the code above and vary by survey?
Screen Shot 2021-01-26 at 11.43.24 PM.png
I should mention that the code above didn't work for me, and I made sure to use JavaScript on a blank descriptive text question that had a page break before and after. I know very little about JavaScript and Embedded Data. I appreciate any help!



icon

Best answer by ahmedA 27 January 2021, 09:47

View original

6 replies

Userlevel 7
Badge +21

I find the code above a little too complicated for the task at hand. The following JS will give you access to the ranked choices in embedded variables from

rank1 
to
rankn

Rather than ordering the choices, it takes the final ordered list as the input and uses its text to populate the embedded data fields.
Qualtrics.SurveyEngine.addOnPageSubmit(function(){
var x = this.getQuestionContainer().querySelectorAll("li");
for(i=0;i var b = x[i].children[1].innerText;
Qualtrics.SurveyEngine.setEmbeddedData("rank"+(i+1),b);
}
});

Badge

https://www.qualtrics.com/community/discussion/comment/33800#Comment_33800So this JavaScript should be written on the rank order question so that when they finish that page it embeds rank1 to rankn?

Userlevel 7
Badge +21

Yes.

Badge


I am trying to carry over the top 3 highest ranked statements from a battery of sliders.
I use above JS statement in the question with all sliders. I have this question in a separate block, and in the workflow I create embedded data for the 3 rank_ fields.
In the next block I then use piped text to call for the top 3 statements ${e://Field/rank_1} from embedded data.
It does not list the statement text. (In fact I don't know whether it recognizes the rank_1 field at all)

...it looks like I am missing something here...

Badge +2

Hello, I am struggling with a similar problem. I have a rank order question with multiple items to drag and rank. I want to add another question right after to this question, but I want it to only be displayed if the rank was given in a specific way. I thought if I somehow put an embedded data that saves their rank order, I can use display logic to check if it was the rank I wanted, and show the second question that way. Thats why I tried to use the JS code given above, but it didn’t work, I don’t see any embedded data field with ranks for me to put into display logic. This may be a very silly question, as i am novice in this, but I would appreciate any help. Thanks :)

Badge

It was not working for me so I used it slightly modified: 

]
Qualtrics.SurveyEngine.addOnPageSubmit(function(){
    var x = this.getQuestionContainer().querySelectorAll("li");
    
    for (var i = 0; i < x.length; i++) {
        // Extract the text content of the second child element of the list item
        var b = x[i].children[1].innerText;
        
        // Set embedded data - don't forget to add empty embedded data named rank1,rank2, rank3 etc.
        Qualtrics.SurveyEngine.setEmbeddedData("rank"+(i+1), b);
    }
});

Works for me :)

Leave a Reply