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

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

  • 14 June 2018
  • 4 replies
  • 246 views

Badge +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?
icon

Best answer by TomG 15 June 2018, 01:09

View original

4 replies

Userlevel 7
Badge +27
In JavaScript the variable this.questionId is the question id.
Badge +1
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.
Userlevel 7
Badge +27
Or you could just define a question id variable at the beginning of your JavaScript:
```
var qid = this.questionId;
```
Userlevel 5
Badge +7
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!

Leave a Reply