setValue()
The setValue() function (client-side and server-side) sets or updates the value of a specific answer.
If you use this function in asynchronous code, call scopeRefresh(), scopeApply() or renderView() to apply the changes.
Syntax
Use this syntax for the setValue() function:
setValue('QUESTION_CODE','ANSWER_CODE', value);
Return Value
The setValue() function returns undefined.
Parameters
All parameters are required.
The setValue() function accepts the following parameters:
-
QUESTION_CODE(string) - Specifies the code of the question for which you want to set the answer. You can find the code in the Code field on the question record. -
ANSWER_CODE(string) - Specifies the code of the answer for which to retrieve the value. You can find the code in the Code field on the answer record. -
value(string or number) - Specifies the answer value to set.
Examples
The following examples show how to use the setValue() function.
Setting a Number as the Answer Value
This example updates the rating to a value of 10 for the feedback question.
setValue('FEEDBACK', 'RATING', 10);
scopeRefresh();
Setting a String as the Answer Value
The example sets "Completed" as a string value for the answer with code STATUS.
setValue('ORDER', 'STATUS', 'Completed');
scopeRefresh();