# Question group

For complex data sets, nest sub-questions within main questions to create hierarchical structures. By doing this, you can easily analyze data about specific medications, including dosages, or family health conditions that affect siblings and parents. Repeat this question multiple times (unlimited, fixed number, or based on another variable answer) so responders can enter information as many times as they need.

Unlike most answers, a compound answer value is stored as an `object`, since it contains multiple parts.

```json
{
	"emergencyContact": {
		"name": "John",
		"lastName": "Doe",
		"email": "john@doe.com"
		"phone": "2345..."
	}
}
```

### Using compound answers in templated strings

If you would like to access one of the parts of a compound in a string template, you can use the `get` [template function](/variable-templating.md#template-formatting-functions).

e.g.

`We'll call {{emergencyContact | get 'phone'}} in case of emergency.` would render `We'll call 2345... in case of emergency.`

### Using compound answers in conditional logic

In the conditional logic editor, you can select fields of a compound question to conditionally show a question, step or question. e.g. If you want to show a boolean question “Renew insurance” when insurance is expired, you can set conditional logic as following.

<figure><img src="/files/99pjxyPjoi6tys0eSSUJ" alt=""><figcaption><p>Setting conditional logic based on compound fields</p></figcaption></figure>

### Repeating question group answers

It is possible to submit multiple answers to a compound question. The repetition count can be set to three different options.

* `Unlimited`: Responders can add as many answers as they want by clicking on +add in the flow itself.
* `Fixed number`:  Set a fixed number of answers for the responder to answer. e.g. 2 emergency contacts in an intake form.
* `Another answer/variable`:  Add a question prior to the compound question that will set the number of answers required in the compound question. e.g. First ask for the number of medicines or pass it via url, then use the compound question to ask for specific questions about the medicines as many times as set in the medication number question.

<figure><img src="/files/o9hQlzLzxVZWNdcAKxvl" alt=""><figcaption><p>Setting repetition style</p></figcaption></figure>

Repeating compound answers appear in form payload as array of objects. e.g.

```json
{
	"numberOfMedicines": 2,
	"medicines": [
		{
			"name": "Medicine 1",
			"dailyDose": 2,
		},
		{
			"name": "Medicine 2",
			"dailyDose": 3,
		}
	]
}
```

### Conditional fields

Fields (sub-questions) in a compound question can be shown based on other answers/variables just like regular questions. If you want to show a field based on other fields in the same compound question, you can set conditional logic in the logic editor. e.g. You have a compound question asking for work experience and you want to ask for “end date” only if the responder quit the job.

<div align="left" data-full-width="false"><figure><img src="/files/t8vK7QEn8XOFFZM1ussJ" alt=""><figcaption><p>Setting conditional logic</p></figcaption></figure></div>

<div><figure><img src="/files/QHk74jIxuwtlqIq0p2xS" alt=""><figcaption><p>End date disabled</p></figcaption></figure> <figure><img src="/files/GUmwlhsWJu5Pju4J3O9W" alt=""><figcaption><p>End date enabled</p></figcaption></figure></div>

### Layout in compound questions

You can have multiple fields in a row in a compound question — just like other questions in a step. You can drag/drop and reorder fields. We currently do not support moving fields in or out of a compound question.

<figure><img src="/files/wxHYlLfW6TwwiadyfKaH" alt=""><figcaption><p>Compound question layout</p></figcaption></figure>

### Copy-pasting compound questions

You can copy and paste compound questions just like other questions, but currently, copying and pasting fields inside a compound question (sub-questions) is not supported.

### Setting compound answers via URL parameter

If you'd like to pass a compound answer into the form instead of requiring the responder to answer a question, you can use object notation like in address answers. e.g.

`https://your-flow-url.com?emergencyContact[name]=John+Doe&email=john@doe.com`

Passing multiple compound answers via url is currently not supported. It will be addressed soon.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.formsort.com/adding-questions-and-content/question-reference/question-group.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
