Getting Labels from Answered Single Select Questions

How do you get survey solutions to return the label associated with a selection made in a Categorical: Single Select question?

Example:
mainWater is a Categorical: Single Select
Piped…10
Bottle…20
Tank…30

I want to create a variable that returns a string -
selectedWater type string

expression-
mainWater == 10 ?
“Piped”
:
mainWater == 20 ?
“Bottle”
:
mainWater == 30 ?
“Tank”
:
null

Is there an easier way to do this? Is there a method something like this -
mainWater.GetLabel(mainWater)

Dear Pierre,

no there is no such method because potentially this will create different behavior when you switch the language of the questionnaire, e.g. from English to French.
If you want to display a value, just use %selectedWater% (that’s percent-selectedWater-percent).
If the codes are 0,1,2,3,4… you can do
new[]{“Piped”,“Bottle”,“Tank”}[(int)selectedWater]
with understanding that you will need to maintain two sets of labels in parallel, and that the language setting will not affect your syntax. Notice indexing starts with ZERO.

Perhaps, if you describe what you intend to do, we can come to a better solution.

Best regards, Sergiy Radyakin

I am glad this solved the issue. Thank you for confirming!

Thanks Sergiy,
I used your recommendation (String[]) and works as expected.
Sorry for all the questions.

All the best,
Pierre

Hello,

I’m struggling with a similar issue here. My problem is the following:
I have a single-select question (combo style) with the name of the household head (lets call it hh_name). Since the survey will be by phone, we will ask the respondent to confirm he is the household head %hh_name%. Let say this question is called hh_confirmation and this is also a single select (1=yes, 2=no). In case the answer is no, then we will ask the respondent its name (string question, resp_name).

Now, I would like to create a variable with the name of the respondent, be it the household head or not (v_name).

But I can’t find a way to access the label of the question hh_name rather than the code.

The expression of my v_name of type string should look like this:

hh_confirmation ==1 ?
//expression to get the string value associated with hh_name
//hh_name, %hh_name% , hh_name.String() do not work
// what could I do?
:
resp_name

Any hint would be very appreciated, since I have face this issue under different circumstances.

Best,

Pascal

@pascaltillie , the linked question contains not the names, but the codes of the persons, as per:
https://support.mysurvey.solutions/syntax-guide/cslanguage/data-types/

So in order to obtain the actual name you need to dereference it using the original source of the items for the linked question.