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

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

  • June 14, 2018
  • 4 replies
  • 375 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.

4 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • Answer
  • June 14, 2018
In JavaScript the variable this.questionId is the question id.

Forum|alt.badge.img+1
  • Author
  • June 15, 2018
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 ●●●●●●●●
  • June 15, 2018
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 ●●●
  • September 10, 2018
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!