getAnswers()
The getAnswers() function (client-side and server-side) retrieves the selected answer values for a question and associates them with the corresponding question and answer code combination.
Syntax
Use this syntax for the getAnswers() function:
getAnswers('QUESTION_CODE');
Return Value
The getAnswers() function returns an object in which each key represents a question and answer code pair, and the corresponding value is the answer selected by the user. The returned object has the following structure:
{
"QUESTION_CODE1/ANSWER_CODE1": "value1",
"QUESTION_CODE1/ANSWER_CODE2": "value2",
"QUESTION_CODE1/ANSWER_CODE3": "value3, value4, value5",
// ...
}
Parameters
The getAnswers() function accepts the question code as a string parameter. You can find it in the Code field on the question record.
Examples
The following examples show how to use the getAnswers() function.
Retrieving Answers for a Question
Suppose you want to retrieve information for the "Select desktop" question with the code DESKTOP. This is an input box question with answers "Select desk type" (TYPE) and "Select desk accessories" (ACCESSORIES), which are a popup table and a popup list, respectively. The popup table uses the desktop type as a reference column, while the popup list includes the type of the accessory type and its color. This example shows how to retrieve answers for the "Select desk type" question.
const desk = getAnswers('DESKTOP');
console.log(desk);
If a user select two rows on the popup table and one option in the popup list, the returned object may be:
{
"DESKTOP/TYPE": "Desktop Series A1000, Desktop Series A2000",
"DESKTOP/ACCESSORIES": "Lamp (Black)"
}