
You’re not over-complicating it. It's totally doable in Canvas Apps. You should not hard-code your questions or dropdown values. You can store them in Dataverse. Below would be my approach that I would use and it should work even for complex trees.
You can have your:
|
Column |
Type |
Purpose |
|---|---|---|
|
QuestionId |
GUID |
Primary key |
|
QuestionText |
Text |
What is shown |
|
QuestionType |
Choice |
Yes/No, MultipleChoice, Number, Text |
|
ParentQuestionId |
Lookup (Questions) |
Which question led here |
|
ParentAnswerId |
Lookup (Answers) |
Which answer triggers this question |
|
DisplayOrder |
Number |
Order in gallery |
|
IsActive |
Yes/No |
Control visibility |
A question will appears only if its' parent answer was selected.
|
Column |
Type |
Purpose |
|---|---|---|
|
AnswerId |
GUID |
Primary key |
|
QuestionId |
Lookup (Questions) |
Which question it belongs to |
|
AnswerText |
Text |
Dropdown / radio value |
|
NextQuestionGroup |
Optional |
Advanced branching |
|
Value |
Text/Number |
Optional scoring |
Each question can have any number of answers.
|
Column |
Type |
|---|---|
|
User |
User / Email |
|
QuestionId |
Lookup |
|
AnswerId |
Lookup |
|
SessionId |
GUID |
galQuestions.Items:
Filter(
Questions,
IsActive = true &&
(
IsBlank(ParentQuestionId) ||
ParentAnswerId in colUserAnswers.AnswerId
)
)
With this:
Dynamic Answer Controls (The Key Insight)
Use one control per question type, not per question
Inside the gallery use:
Switch(
ThisItem.QuestionType,
"YesNo", radYesNo,
"MultipleChoice", drpMulti,
"Text", txtAnswer,
"Number", txtNumber
)
Only the matching control will be visible.
How each dropdown will get its own answers
I think this is the part you were stuck on.
Dropdown inside gallery, use:
Items = Filter(
Answers,
QuestionId = ThisItem.QuestionId
)
Use something this OnChange of dropdown/radio then new questions appear automatically.
Collect(
colUserAnswers,
{
QuestionId: ThisItem.QuestionId,
AnswerId: drpMulti.Selected.AnswerId
}
)
You will have it with table setup because:
Hope this helps!