Selected additional items from a roster (random selection)

Please excuse my ignorance on this one. I have a number of values captured in a roster, including age. I am trying to extract the age of my selected respondent. I am able to get their name, but am at a loss as to how to get the age associated with that row, as I need to use the age of the selected respondent later.,

Any suggestions would be appreciated.

-davidp-

It is hard to give you an answer without seeing the structure of your questionnaire and question types you are using. You can create and share the questionnaire, or attach a screenshot, or outline the structure using markup here.

But if for the “selected respondent” you are using single select linked question, when you can access the code of this person like this: q1[0] or q1.Last(), where q1 is a variable name for the question.
Assuming you have a roster members typically triggered by a list question with names, you can access whole roster row with index operator like this: members[1]. That will return you an object with all answers for a member with code 1. To get age simply write members[1].age.
To get access to the age of the selected respondent you can combine both expressions like this: members[q1.Last()].age or members[q1[0]].age

1 Like

David doesn’t show the questionnaire he works with, but he probably refers to the public example on selecting a respondent randomly “Public example Random demo” .

While the purpose of that example was to select a person randomly and display the name of the selected person for the remainder of the interview, in the course of doing so we select the code of that person.

https://designer.mysurvey.solutions/questionnaire/details/7e6f99e3744e4ed9b56879482d99be04/chapter/8ae67f9587324f00bd24d35a71526833/variable/5f3b17a370b64f4eb3a52c14dafcea12

Refer to calculated variable randomRowcode.

David can now obtain the other characteristics of the selected person by applying indexing to the roster of the members

MEMBERS[(int)randomRowcode].age ---- will be the age of the randomly selected person.

I have changed the public example to indicate the age of the person after selection, and this age stored in a variable can be further used in skips and validation conditions.

Best, Sergiy

1 Like

Perfect modification of the example code… nice and clear. Thank you Sergiy.