How can i set "side-by-side" question type variation "SBSMatrix" values using the QX API? | XM Community
Solved

How can i set "side-by-side" question type variation "SBSMatrix" values using the QX API?

  • 18 July 2023
  • 3 replies
  • 113 views

Userlevel 3
Badge +4

I have a question of question type “side-by-side” I’d like to set the values for. The question looks in the UI like this.

 


Via the question object I can get the question info. It contains the question type (QuestionType “SBS”) and variation (Selector “SBSMatrix”) which allow me to identify this question type variation as such one.
 


The challenges I have right now:

- How can I get meta data about the types of the column values (first column is string type, second column is integer type)? This is required to add conditional business logic based on actual question type variation.

- What Qualtrics API (q.setChoice<something>) can I use in general to set values for this question type variation in survey preview mode a reliable way (means with a unique identifier for specific matrix cells)? This is required to set the values in a reliable way.

 

icon

Best answer by thinwybk 21 July 2023, 16:28

View original

3 replies

Userlevel 7
Badge +27

I was having trouble setting values for Side-by-Side with setChoiceValue, but setting values by the Id of the input with jQuery works. For a Side-by-Side with 2 columns, 1 Column Answer per column, and both set to Open Ended Text, try adding to the below to the OnReady of the question’s JavaScript.

The Id of an input will look like QR~QID29#2~3~1~TEXT where:

#2 is the column number

~3 is the row number

~1 is the Column Answer number

var qid = this.questionId;
var input1 = document.getElementById("QR~"+qid+"#1~2~1~TEXT");
jQuery(input1).val("Text 1");

var input2 = document.getElementById("QR~"+qid+"#2~3~1~TEXT");
jQuery(input2).val("Text 2");

 

Userlevel 3
Badge +4

@Tom_1842 The official API cannot support setting values with setChoiceAnswerValue( choiceId answerId value ) https://api.qualtrics.com/82bd4d5c331f1-qualtrics-java-script-question-api-class#methods here cause we don’t have answers ids here. Means we cannot identify cells.

Your workaround suggestion works for me as well if the matrix cells are of type string (→ TEXT). In other cases the id will be different I guess.

Userlevel 3
Badge +4

@Tom_1842 The way how rows and rows need to be indexed is like usual rows via choices. columns via answers is different from the usual pattern.
 

 


I’d assume that for other side by side matrices and data types the id will just lack “~TEXT” means “QR~QID#1~9~1”.

Leave a Reply