Is there an api(code)to get question Id? | Experience Community
Skip to main content
Solved

Is there an api(code)to get question Id?

  • Jun 14, 2018 1:13 PM UTC
  • 4 replies
  • 421 views

Forum|alt.badge.img+1
I see that we can get SurveyID of the survey by using "${e://Field/SurveyID}". Is there an api(code)to get question Id in given page?

Best answer by TomG

In JavaScript the variable this.questionId is the question id.
View original

4 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • Answer
  • Jun 14, 2018 11:09 PM UTC
In JavaScript the variable this.questionId is the question id.

Forum|alt.badge.img+1
  • Author
  • Jun 15, 2018 2:23 PM UTC
Thank you TomG. Was aware of this and tried many times earlier. Always giving "undefined". Working on clickNextButton() made me realize that "this" is undefined within your js functions. You need to declare it outside of functions as var that = this and use that.questionId within your javascript functions.

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • Jun 15, 2018 3:02 PM UTC
Or you could just define a question id variable at the beginning of your JavaScript: ``` var qid = this.questionId; ```

JeremyK
Level 3 ●●●
Forum|alt.badge.img+7
  • Level 3 ●●●
  • Sep 10, 2018 10:03 PM UTC
Hey Sandy, I understand this is an old issue, but I just ran into the "undefined" problem myself. My problem took me 2 tries to run down; JavaScript is a case sensitive language and I'd typed a lower case 'i' in ID; i.e. my variable was "var qid = this.questionid", which will throw a "undefined" every time :) Just wanted to throw this out there in case it was of use to you!