How can I set the value of a "slider" question using the QX API? | XM Community
Skip to main content

I’ve a slider like the following one defined in the survey.

 


This corresponds to a question object with a single choice → RecodeValue (runtime.Choices) and consisting of answers (runtime.Answers) like follows:
 


Instead of using some hacky workaround to set the slider value (e.g. using some jQuery) like described in other threads I’d like to set the value explicitly via the QX API.

I can get the choice and the corresponding RecodeValue.
 

But I cannot set the value using the QX API no matter what API of the available options for this question type I use:
 


How can I set values using the QX API?

Try adding the below to the OnReady section of the question’s JavaScript. It will set the value of the 1st slider to 44.

this.setChoiceValue(1,"44");

 


@Tom_1842 The `this.setChoiceValue(1, "44");` syntax does not work for me for that question type variant.


@Tom_1842 Actually nothing from the official API docs worked for me so far:

I have
 


and tried everything from the official API docs (https://api.qualtrics.com/82bd4d5c331f1-qualtrics-java-script-question-api-class#methods)

- setChoiceAnswerValue ( choiceId answerId value)

- setChoiceValue (choiceId isubId] value )

- setChoiceValueByRecodeValue (recodeValue VsubId] value )

which made sense somehow including probably undocumented variants already without success.

For all of those I got completely mis-leading return of true (“true if success”) and the UI does not show the updated value:


Same for all other variants I tried yet.
 


@Tom_1842 I tried to workaround using jQuery to set the slider input element value. However eve this does not work ATM. The input element has id “QID27~9~realslider”.

 


I get the value but if I try to set it the value in the UI is not set/updated correspondingly. It does not matter if I consider the grid setting (here: value of 10 → “50”) or not.
 

 


@Tom_1842 Actually nothing from the official API docs worked for me so far:

I have
 


and tried everything from the official API docs (https://api.qualtrics.com/82bd4d5c331f1-qualtrics-java-script-question-api-class#methods)

- setChoiceAnswerValue ( choiceId answerId value)

- setChoiceValue (choiceId isubId] value )

- setChoiceValueByRecodeValue (recodeValue VsubId] value )

which made sense somehow including probably undocumented variants already without success.

For all of those I got completely mis-leading return of true (“true if success”) and the UI does not show the updated value:


Same for all other variants I tried yet.
 

@Tom_1842  Those API calls do not make much of a sense actually. However just for the sake of completeness:

 


Hmm it is working on my end. I see that your slider set up is a little different than mine. I don’t see any mention of “RealSlider”. How is you slider set up? Below is what I see, with value 44 set by 

this.setChoiceValue(1, "44")

 


@Tom_1842 I’ve opened the survey in “overall survey preview”. I don’t use “single question preview” cause it does not work in my setup.
Other than that I could only think of that the QX UI could vary depending on QX instance/runtime deployed in some region. I’m located in Germany. Other than that I don’t know what else it could relate to.

The slider is pretty standard actually:
 

 


My screen shot is also from the overall Survey Preview. It is working for me in the attached QSF if it helps. Also in that QSF is another option that I think will work for you to set the value of the sliders. It uses Embedded Data fields to set Default Choices for the sliders.

To give it a try, create the Embedded Data fields of “slide1”, “slide2”, and “slide3” and place them at the top of the Survey Flow. Write in the values “22”, “44”, and “66”. Then create a Slider question with 3 sliders and enable “Show Values”. Then select “Default Choices” towards the bottom of Question behavior. Using the blue arrows at the right of the sliders, pipe in the Embedded Data fields of “slide1”, “slide2”, and “slide3”, like in the below:

And then in the survey:

 


@Tom_1842 Thanks a lot for the hint. Some data we profile with EmbeddedData already. In this specific case however it’s not possible for us to use EmbeddedData based pre-filling. We need to go via the official QX API or using some browser based workaround.


Leave a Reply