Pipe text from ranked items | XM Community
Skip to main content
I am trying to pipe ranked items into following questions, and add some Javascript code because there are also default items that might be overlapped with the ranked items. So I understand that I can access to the highest ranked one with ${q://QID28/ChoiceGroup/ChoiceWithHighestValue}. But what about, say, the second highest? After reading this post, http://kurtmunz.com/2015/05/28/rank-order-carry-forward-in-qualtrics-with-javascript/, I guessed something like, ${q://QID28/ChoiceDescription/2}, might work, but it did not. Does anyone have a good idea about this matter? Thank you so much for helping.
No what you mentioned will not work for ranking question. You have to write loop in JavaScript and store your ranks say rank1,2,3... In embedded variablles. Than you can use these embedded variables for piping.
You are right ! I created embedded variables and wrote the loop. The thing I'm missing here is that I can't locate *rank 2* to put it in the embedded variable. (not rank 1 because ${q://QID28/ChoiceGroup/ChoiceWithHighestValue} works for that)
Since you have to find rank2, rank3.. along with highest rank. Silo it will not work. Make two arrays one with codes of ranking question and one with labels. Compare codes by running loop and store rank1, rank2.... And than use labels for piping.
sorry, I don't understand your answer.. What do you mean by *codes* of ranking question, and *labels* for what? For now, I think I don't have nothing to compare because I don't know where are all values are.



The blog post I copied above implies that ${q://QID28/ChoiceNumericEntryValue/2} has ranking for the second highest, and ${q://QID28/ChoiceDescription/2} has the description for the second highest; but it seems not because simply piping '${q://QID28/ChoiceDescription/2} gives you a blank.



My plan was to make a 2d array like,



[

[rank 1, description 1],

[rank 2, description 2],

[rank 3, description 3],

[rank 4, description 4],

[rank 5, description 5],

[rank 6, description 6],

]



, delete some of the rows with a loop, and sort by the first column, and put the second column in the embedded variables. But again, I don't know where I can find the values for all those elements. Is this related your answer somehow?
@paniked83,



${q://QID28/ChoiceNumericEntryValue/1} is the rank of the first item,

${q://QID28/ChoiceNumericEntryValue/2} is the rank of the second item,

etc.



So, you need to sort the items based on those ranks, then the second element in your sorted array is the item that was ranked 2nd.
@TomG Oh okay, I thought ${q://QID28/ChoiceNumericEntryValue/1} was the value for the *first ranked* item instead of the rank of the first item, which is a stupid negligence. Thank you!!
@TomG Actually, I ran into another problem. So, the items respondents are asked to rank are in fact *carried forward* from a preceding question. That is, I asked them to choose 5 out 20 in Q27, and then asked them to rank those 5 in Q28. In that case, it doesn't seem that ${q://QID28/ChoiceNumericEntryValue/1} is the location I was looking for. I perfectly works when there's no *carried forward* part. Do you have any idea by any chance?
Hi @paniked83

In the successor question , only show the 5 items you have stored in embedded variable , rather than all 20 by carry forward.
Hi @bansalpeeyush29, thank you for coming back to this thread. Yeah, that makes sense. Still, ${q://QID28/ChoiceNumericEntryValue/1}, which should be the first item, doesn't contain any value when items were carried over from QID27.
@bansalpeeyush29 I've been testing this for tens of hours. It's okay if you don't want to help.
@paniked83 i posted wrong message so changed it to "test", i am not refering it for you. Sorry 😞
create variable Rank1 to Rank5 as embedded and pipe these in your next question. Like in below i am using 2 arrays, one with codes another with there labels. Than comparing and storing top 5 ranks in embedded variables. Add code like below on onready next to your question in any other descriptive text or question and hide that.

'

var arr1 = [codes(ranks for each item)...]



var arr2 = ["label1", "label2"];

/**arr2 store text for your rank itmes...



for( var i=0; i<arr1.length; i++)

{

//var txt= new String();

var code1 = arr[i];



if(code1 == 1)

{

var Label1 = arr2[i];

//txt = txt + "Rank 1:" + Label1

Qualtrics.SurveyEngine.setEmbeddedData('Rank1', Label1);

}



if(code1 == 2)

{

var Label2 = arr2[i];

//txt = txt + "Rank 2:" + Label2

Qualtrics.SurveyEngine.setEmbeddedData('Rank2', Label2);

}



if(code1 == 3)

{

var Label3 = arr2[i];

//txt = txt + "Rank 3:" + Label3

Qualtrics.SurveyEngine.setEmbeddedData('Rank3', Label3);

}



if(code1 == 4)

{

var Label4 = arr2[i];

//txt = txt + "Rank 4:" + Label4

Qualtrics.SurveyEngine.setEmbeddedData('Rank4', Label4);

}



if(code1 == 5)

{

var Label5 = arr2[i];

//txt = txt + "Rank 5:" + Label5

Qualtrics.SurveyEngine.setEmbeddedData('Rank5', Label5);

'
> @paniked83 said:

> @TomG Actually, I ran into another problem. So, the items respondents are asked to rank are in fact *carried forward* from a preceding question. That is, I asked them to choose 5 out 20 in Q27, and then asked them to rank those 5 in Q28. In that case, it doesn't seem that ${q://QID28/ChoiceNumericEntryValue/1} is the location I was looking for. I perfectly works when there's no *carried forward* part. Do you have any idea by any chance?



For carryovers the piped values are:

${q://QID28/ChoiceNumericEntryValue/x1}

${q://QID28/ChoiceNumericEntryValue/x2}



If you carryover the carryovers they are:

${q://QID28/ChoiceNumericEntryValue/xx1}

${q://QID28/ChoiceNumericEntryValue/xx2}
@bansalpeeyush29 That's okay. I really appreciate your help!

@TomG Your answer really helped! Although I found out that, when 20 items were carried over and only 5 of them were chosen, there are still labels from x1 to x20, but that the label doesn't contain a value when a corresponding item was not chosen. For example, if 6th item was chosen, 7th wasn't, and they are carried over to the next question, it seems that *x6* contains the value for 6th item, and *x7* simply doesn't exist. Do you think it's correct? That changes my coding, but explains why it didn't work.
> @paniked83 said:

> @bansalpeeyush29 That's okay. I really appreciate your help!

> @TomG Your answer really helped! Although I found out that, when 20 items were carried over and only 5 of them were chosen, there are still labels from x1 to x20, but that the label doesn't contain a value when a corresponding item was not chosen. For example, if 6th item was chosen, 7th wasn't, and they are carried over to the next question, it seems that *x6* contains the value for 6th item, and *x7* simply doesn't exist. Do you think it's correct? That changes my coding, but explains why it didn't work.



Yes, that's correct. The carryover items maintain their original choiceId's with an 'x' added in front. Since you don't know which ones were selected, you need to check them all and throw out the ones that are empty, then sort the remaining ones.
> @TomG said:

> > @paniked83 said:

> > @bansalpeeyush29 That's okay. I really appreciate your help!

> > @TomG Your answer really helped! Although I found out that, when 20 items were carried over and only 5 of them were chosen, there are still labels from x1 to x20, but that the label doesn't contain a value when a corresponding item was not chosen. For example, if 6th item was chosen, 7th wasn't, and they are carried over to the next question, it seems that *x6* contains the value for 6th item, and *x7* simply doesn't exist. Do you think it's correct? That changes my coding, but explains why it didn't work.

>

> Yes, that's correct. The carryover items maintain their original choiceId's with an 'x' added in front. Since you don't know which ones were selected, you need to check them all and throw out the ones that are empty, then sort the remaining ones.

>



Great! Then, I think I can do this. Again, thank you so much!
I thought this would help me... I have a similar question. The results are not working.

First question is rank order 22 items (not a carryover question). The second question is to be a Constant Sum based on the results of the first question. My first option is ${q://QID380/ChoiceGroup/ChoiceWithLowestValue} , which will give me the Previous Answer ranked #1.



I can even use the preselected ${q://QID380/ChoiceGroup/ChoiceWithHighestValue} on the last answer... but nothing inbetween. Help?
> @BannonStanks said:

> I thought this would help me... I have a similar question. The results are not working.

> First question is rank order 22 items (not a carryover question). The second question is to be a Constant Sum based on the results of the first question. My first option is ${q://QID380/ChoiceGroup/ChoiceWithLowestValue} , which will give me the Previous Answer ranked #1.

>

> I can even use the preselected ${q://QID380/ChoiceGroup/ChoiceWithHighestValue} on the last answer... but nothing inbetween. Help?



Please see this post
> @bansalpeeyush29 said:

> Add code like below on onready next to your question in any other descriptive text or question and hide that.



Where do I add the codes???



I have a similar question. I wanted to display four statements as ranked in a previous question and ask for further comments. No knowledge of JavaScript. Would this solution be relevant to my question? Can you please explain where exactly to add the codes?

Leave a Reply