Nested switch statements in a command

Hi, I have a command which will be used to fill in a certain form with nested subforms which looks something like this.

'fill in form': command {
'question': stategroup (
     'answer I' { }
     'answer II' {
         'question 1.1': stategroup (
		'Yes' { }
		'No' { }
	)}
)
} => update .... = create (
    'question' = switch @ .'question' (
			| 'Answer I' => create 'Answer I' ( )
			| 'Answer II' => create 'Answer II' (
				'question 1.1' = switch @ "path to specify" (
					| 'Yes' => create 'Yes' ( )
					| 'No' => create 'No' ( )
				)
			)
		)
)

I could not figure out which path I should specify at “path to specify” to find the answer for question 1.1 so I can execute the switch statement on the answer of question 1.1.

Just having the .'question1.1' or '.question' .'question 1.1' does not seem to work

Hi Quentin, you can use stategroups for this, as you are trying to do, but the resulting application will be fairly limited, because you can only see and answer the questions that were created when designing the application (by you). Now if you use stategroups, there is no path to specify there, you need to design a specific place to store the answer.

More likely is that you want (and already have) collections of questions and answers. Can you add those to the code example? I can then help you change the command to better fit what you want

Hi,

Thank you for your reply

I am actually just trying to implement a simple (hard-coded) form, where for some specific answers we need to ask some extra questions. For example for the question: “do you want to drink alcohol?”, we would want to ask if the person is 18+ if answered with yes, but if answered with no, we can skip that question.

Where would in the above example the answer of question 1.1 be stored and how would I access it at "path to specify"? Or are additional steps needed to make this work?

Thank you!

@Quentin you can access the answer to question 1.1 like this:

} => update .... = create (
    'question' = switch @ .'question' (
			| 'Answer I' => create 'Answer I' ( )
			| 'Answer II' as $'q1ans' => create 'Answer II' (
				'question 1.1' = switch $'q1ans'.'question 1.1' (
1 Like