Display/Enable conditions

Display/Enable conditions

Compose Enterprise is going through a design update. The illustrations on this page might be of the old design, but the information is up to date. Thank you for your patience during this update!

Norsk

It is possible to add conditions to elements and pages in a form. With these conditions, you can display (or enable) different questions based on the answers given by the end-user.

Say, if a question asks the end-user if they have pets. If their answer is Yes, you can display questions asking for more information regarding their pets. If the answer is No, the pet-related questions stay hidden and you don’t have to fill the screen with content the end-user has no need to address. In this case you would set a display condition on the questions you want to display. And these questions will only be displayed if the condition is fulfilled, aka. that the answer to the “pet question” is Yes.

There are also enable conditions. Before the condition is fulfilled, the question will be read-only. After the condition is fulfilled, the question will be enabled so the end-user can answer/edit the questions.

Inside the Form Builder, all form elements and pages have a tab in the Properties panel called Conditions. Here you can script conditions in the code windows from scratch with Groovy code, or you can click Open to open the Condition Builder.

In the Condition Builder you can set conditions completely without coding. The coding windows are a playground for service builders wanting to create more advanced conditions, and also to display the equivalent code of the conditions set in the Condition Builder.

Add a display (or enable) condition

Note: As setting enable conditions contain the same logic as for display conditions, only display conditions are showcased.

Let’s say the end-user is filling out travel details. If they are travelling with pets, it is necessary to declare how many pets they are travelling with. We want to hide the pet-related questions until the end-user has said that they are traveling with pets. See the tentative form in the screenshot underneath. Let’s select the How many pets? question, then click the Conditions tab in the properties panel and Open the condition builder.

When you have opened the condition builder, click (+) to Add condition.

In the first dropdown list select the question you want to base your condition on.

When you have selected the question, the available methods for this question will be displayed in the additional dropdown lists, and you can choose from these when creating your condition. The available methods rely on the question type and input validation.

For this example we want to display the question, if the end-user has checked off Pets in the question Are you travelling with any special baggage?. Choose therefore the option Pets in the last dropdown list.

The condition reads that the question will be displayed if the Are you travelling with any special baggage? answer equals Pets. The condition is completed and we can press OK to save the condition.

When the condition is saved you will be able to see the script used under Display Condition.

Note: Take a closer look at the condition script Q1?.answer?.value?.equals(“1”). In the Condition Builder, we chose the option label Pets, but the script says Q1 must equal 1. That is because the answer value (not the option label) equals 1.

Click Save Draft and create a version of the form to make the changes available to use in a workflow.

Scripting conditions

Scripting conditions from scratch can seem a little hard if you’re not experienced with Groovy code. Therefore it is highly encouraged to use the Condition Builder to add some conditions, and then click the switch to code button to convert those conditions to Groovy code.

That way, you can generate Groovy code similar to the conditions you want to script without having to start from scratch!

A proper overview of scripting conditions can be found in the Condition scripting user guide.