I have 6 embedded variables - is it possible to get the ranking of each of the variables and put those ranks in 6 new variables with JavaScript (or another method) please?
e.g. if AGap=25, BGap=10, CGap=15, DGap=0, EGap=30, FGap=20
I would want to get:
ARank=2, BRank=5, CRank=4, DRank=6, ERank=1, FRank=3
Many thanks, Michael
What is the JavaScript to rank 6 Embedded Variables
Best answer by Rudi
Hi Mike
this should do the job
Qualtrics.SurveyEngine.addOnload(function()
{
//Step 1
//object with the keys and values
let dicValues = {
"a" : Number("${e://Field/aGap}"),
"b" : Number("${e://Field/bGap}"),
"c" : Number("${e://Field/cGap}"),
"d" : Number("${e://Field/dGap}"),
"e" : Number("${e://Field/eGap}"),
"f" : Number("${e://Field/fGap}"),
}
// Step 2
// Create the array of key-value pairs
var items = Object.keys(dicValues).map(
(key) => { return [key, dicValues[key]] });
// Step 3
// Sort the array based on the second element (i.e. the value)
items.sort(
(first, second) => { return second[1] - first[1] }
);
// Step 4
// Obtain the list of keys in sorted order of the values.
var keys = items.map(
(e) => { return e[0] });
console.log(keys);
// step 4
//iterate through the sorted keys and write the rank into embedded data fields
for(let i=0;i
}
});
Best regards
Rudi
Sign up
Already have an account? Login
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login to the Community
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
