Set last two digits of a field as embedded data | XM Community
Skip to main content

This is kind of a weird request, but is there any way to look at the value of something (specifically a Scoring score) and set a separate embedded data field that only uses the last two digits of the score?

So if a score was 218, for example, the regular Score field would still show 218, but in a new embedded data field (let’s say shortscore) it would save 18 instead of 218?

For my attention checks they get 1 point for a correct answer and 100 points for an incorrect answer, which makes it easy to se both how many questions they got right (since there’s never more than 25 questions total) and how many they attempted overall. So the score gets saved as 218 if they answered 18 right and got 2 wrong. But I’m trying to also generate a percentage correct that can beshown to them at the end of the survey, so I want to create a separate field for just the last two digits. Is this possible?

Thanks!

You could assign 0 for an incorrect answer and 1 for a correct one in your scoring and then create an ED with $e{ gr://SC_xxx/Score / gr://SC_xxx/Items * 100}


@vgayraud I know that would be the default, but because the scoring happens in loop and merge I need to be able to see how many questions were answered incorrectly (the number of questions asked varies by condition and some people may skip questions) so 0 doesn’t work. I have that type of math in use for the overall completion score, but the attention check questions very specifically are different. I could recode all the scoring to make correct and incorrect two different scoring categories, but I’d rather not do that if there’s a way I can just grab the last two digits with js or something.


Probably something along those lines with the ED score containing your score and the ED lastDigits to receive your result.

 

Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/

var score = "${e://Field/score}";
var lastDigits = score.slice(-2);
Qualtrics.SurveyEngine.setEmbeddedData("lastDigits", lastDigits);

});

 


Leave a Reply