Math Results not showing up | XM Community
Solved

Math Results not showing up

  • 26 July 2021
  • 5 replies
  • 29 views

Hi,
I'm trying to do a math operation where the survey respondent starts with $x. A choice that the survey respondent makes should deduct $y from this initial amount (for simplicity, let x and y be 1). I am trying to show the remaining amount dynamically using Qualtrics Math operations or Javascript. However, during testing, the results of the math operations are showing up as blank.
How can I fix this? Would really appreciate all the help, thanks!

This is my code in Javascript:
Initial Embedded Data.PNG
Javascript Math Eqn.PNGThis is the logic I'm using in the question text for the math operation to display:
Piped Text in the question.PNGThis is the blank result I get during testing:
Javascript Math not showing up.PNG

icon

Best answer by Lokendra 30 July 2021, 02:24

View original

5 replies

Userlevel 4
Badge +26

Hi Lokendra,
In this case, Javascript triggers after page load henceforth it will not dynamically updated on the same page, however if you refer the variable on the next page - you will be able to see the calculation result.
In your case you can achieve this without using JavaScript paste below code in the question text:
$e{e://Field/P2endowment + e://Field/DecisionCost}
If this works for you, please accept this as an answer.
All the best for your project!

Hi Cbhavsar,
Thanks for the tip, but I've already tried using in-built Qualtrics math operations. The same problem as above occurred. Any instance where I used math to get a result dynamically showed up as blank during testing.
Qualtrics Math Problem 2.PNG
image.png

Userlevel 7
Badge +21

Qualtrics returns all values as stings and JS doesn't know how to perform subtraction on strings. Check your console you'll be getting some errors related to it.
Wrap your values so that JS knows they are numbers like this: Number(Qualtrics.SurveyEngine.getEmbeddedData(...,... ))

Userlevel 4
Badge +26

Hi, I am not sure why in your embedded shows 'Number Set' field. I tried the below code, it is working fine. Can you try with this and then procced further:
image.png

https://community.qualtrics.com/XMcommunity/discussion/comment/39323#Comment_39323

Thanks to everyone who left a comment here to help!
I believe the issue was with me re-using embedded data objects based on if statements. I re-did the survey again using a separate embedded data object for each individual calculation and it worked.

Leave a Reply