Rules
Rules let a form or workflow react to what people do. A rule can show or hide a question, make it required, fill in a score, show a warning, stop a save, open a particular form next, or email someone. You build rules by snapping blocks together, a bit like the children's coding tool Scratch.
This chapter explains the two ways a form can decide what it shows, how to switch between them, the blocks editor, every block, worked examples, daily scheduled rules, and emails.
Classic settings or rules from blocks
Forms
Each form chooses how it decides what shows and what must be answered. Open the form in the form designer and click the Rules tab. At the top it says This form uses: with two choices:
| Choice | How it works |
|---|---|
| Classic settings | Each question's Show only when and Required when settings decide what shows and what must be answered. |
| Rules from blocks | You build rules with blocks on the Rules tab. The Classic settings are replaced by these rules. |
New forms start on Classic settings. Classic settings are simpler and cover most needs: "show this question when that button is picked". Rules from blocks can do more: compare numbers, add up scores, show messages, refuse a save, and send emails.
Workflows
Each workflow has its own rules, separate from its forms' rules. Open the workflow and click the Rules tab. It says Rules for this workflow: with Off and On.
- Off (the start for new workflows): "Rules are off: the workflow runs as its forms and buttons say."
- On: the blocks editor appears, with the workflow blocks.
Rules you made before are kept when you switch Off, and come back when you switch On again.
Switching a form to rules from blocks
- Open the form and click the Rules tab.
- Choose Rules from blocks.
- kep7 turns the form's Classic settings into blocks automatically, so nothing is lost. (If the form already has blocks from an earlier time, those are used instead.)
- Change or add rules in the blocks editor.
- Click Save draft, then Publish… when ready.
While blocks are on, a question's or element's settings no longer show Show only when or Must be answered only when. Instead they say to use the Rules tab.
Switching back to Classic settings
- On the Rules tab, choose Classic settings.
- Each question's Show only when and Required when settings are used again.
- The blocks are kept but not used. kep7 says: "This form's blocks are kept, and come back if you choose blocks again."
Ready-made rules
The Ready-made rules box at the top of the Rules tab builds common rules for you from a short sentence. Choose a rule, fill in its sentence with the dropdowns, and click Add this rule. kep7 adds it to the blocks below ("Added. It's in the blocks below, where you can change it."), so you can change it later like any rule. Adding one to a form on Classic settings switches it to rules from blocks (the Classic settings are turned into blocks first, so nothing is lost); adding one to a workflow switches its rules on. When a question's buttons come from a list, the rule offers that list's answers. A Mark a picture question with kinds of mark offers its kinds (the answer "is" Burn when a Burn is marked), and a Barcode question that looks codes up in a list offers its codes.
On a form:
| Ready-made rule | The sentence |
|---|---|
| Ask for an explanation when an answer meets a condition | When *question* is *answer* (or is less than, more than… a value), show *the question to explain* and make it required. Otherwise hide it. |
| Calculate a total | Set *the question holding the total* to the total of: *the questions ticked*. |
| Show a warning when an answer meets a condition | When *question* is *answer*, show a warning saying *your words*. |
| Don't save when an answer meets a condition | When saving, if *question* is *answer*, don't save, and say *your words*. |
| Email someone when an answer meets a condition | When saving, if *question* is *answer*, email *who*, with a subject and message. |
On a workflow:
| Ready-made rule | The sentence |
|---|---|
| Open a follow-up form after a particular answer | When *form* is saved, if *question* is *answer*, open *another form* next. |
| Email someone if an expected entry is missing | Every *day* at *time*, if nobody has recorded *form* today, email *who*, with a subject and message. |
| Flag information that has become out of date | When it opens, if nobody has recorded *form* in *the period*, show a warning saying *your words*. |
| Email someone when an answer meets a condition | When *form* is saved, if *question* is *answer*, email *who*. |
If something in the sentence is missing, it says what, e.g. "Please choose a question."
The blocks editor
The editor says: "Drag blocks from the left to build rules. Each rule starts with a when block. Rules save with the form (or workflow) and are checked when you publish."
Parts of the editor
- Categories down the left side (When, Do or Workflow, Logic, Answers, Maths, Words, Time and people). Click one to see its blocks.
- The workspace, where you build rules.
- Zoom controls (+ and −), and a bin for removing blocks.
Building a rule
- Click the When category and drag a "when" block onto the workspace. Every rule starts with one, and a "when" block can only go at the top of a rule.
- Click another category and drag a block into the "do" gap of the "when" block. The block snaps into place.
- Keep adding blocks. Blocks with a gap on their side take a value (such as a number or an answer); blocks with notches top and bottom are actions that stack in order.
- Use the drop-downs on each block to pick the question, form or option.
- Click Save draft on the form or workflow. Rules save with it.
Zooming and tidying
- Use the + and − controls, or hold Ctrl and turn the mouse wheel, to zoom. kep7 remembers the size in this browser.
- Drag a block to the bin to remove it. Dragging a block also drags everything attached under it.
Form blocks
These blocks are available on a form's Rules tab.
When
| Block | When it runs |
|---|---|
| when answers change | Whenever an answer changes, and again when the form is saved |
| when it opens | When someone opens the form. Use it for starting answers and messages. |
| when the form is saved | When Save is pressed, before the entry is kept |
Do
| Block | What it does |
|---|---|
| show [question or element] | Shows it |
| hide [question or element] | Hides it. A hidden question's answer isn't kept. |
| make [question] required | The question must be answered |
| make [question] optional | The question can be left empty |
| set [question] to … | Sets a question's answer, for example a score |
| show [a note / a warning / good news] saying … | Shows a message at the top of the form |
| don't save, and say … | Stops the save and says why (use it in a "when the form is saved" rule) |
| email [to] subject … message … | Sends an email (see Emails from rules) |
Logic
- if … do: does something only when a condition is true.
- if … do … else: does one thing when true and another when not.
- A ready-made comparison number from [question] < 5. Change the question, the sign and the number.
- An empty comparison, with =, ≠, <, ≤, > and ≥.
- and / or, to join conditions.
- not, to turn a condition around.
- true / false.
Answers
| Block | What it gives |
|---|---|
| answer to [question] < 5 | True when the answer compares as chosen. < and > use the answer as a number; = and ≠ use it as given. |
| answer to [question] | The answer, as given |
| number from [question] | The answer as a number: a button's value from its list, or several added up |
| [question] is [answer] | True when this button is the answer (or one of those picked) |
| [question] is answered | True when it has an answer |
| how many picked in [question] | How many buttons are picked |
| for each answer picked in [question] do | Repeats for each button picked (up to 100 times) |
| the answer picked | Inside "for each answer picked": that answer |
| entries of this form [period] by [me / anyone] | How many entries the person can see, today, this week, in the last 7 days or in the last 30 days |
| fill-in [word] | A fill-in value the project or workflow gives the form |
Maths
- A number.
- Add, take away, times, divide, and power.
- Round (also round up and round down).
- smaller of / bigger of / average of … and ….
Words
- A piece of text.
- Join pieces of text together.
- The length of some text.
- Whether text is empty.
- … contains … (true when the words, or the answers picked, include these).
Time and people
- the [hour (0-23) / minute / day of the week (Mon 1 - Sun 7) / day of the month / month / year]: now, where the project is.
- today is [a weekday / a weekend day / Monday … Sunday].
- the person's [name / email]: who is filling it in. Blank on anonymous links.
Workflow blocks
Workflow rules look across all the workflow's forms. Questions in drop-downs are named "Form: question". Workflow rules can't show, hide or require questions; those are form rules.
When
| Block | When it runs |
|---|---|
| when it opens | When someone opens the workflow |
| when [any form / a form] is saved | When a form in this workflow is saved |
| every [day / weekday / weekend day / Monday …] at [17:00] | Once a day at that time (see Scheduled daily rules) |
Workflow
| Block | What it does |
|---|---|
| open [form] next | After saving, opens this form |
| offer a button for [form] saying … | Shows a button that opens this form (up to 6) |
| end the workflow | After saving, goes back to the project's page |
| show [a note / a warning / good news] saying … | Shows a message |
| don't save, and say … | Stops the save and says why |
| email [to] subject … message … | Sends an email |
The Logic, Answers, Maths, Words, and Time and people categories are the same as for forms. In a workflow, entries of lets you pick which form to count.
Worked examples
Example 1: low sleep needs an explanation
Goal: if the answer to "Sleep" is less than 5, show and require "What happened overnight?" and show a warning. Otherwise keep that question hidden.
Questions show unless a rule hides them, so the rule needs to hide the question when sleep is 5 or more.
- On the form's Rules tab, choose Rules from blocks.
- From When, drag when answers change onto the workspace.
- From Logic, drag if … do … else into its "do" gap.
- From Answers, drag answer to [question] < 5 into the "if" gap. Pick "Sleep". Leave the sign as < and the number as 5.
- From Do, drag show into the "do" gap of the "if" block and pick "What happened overnight?".
- Under it, drag make [question] required and pick "What happened overnight?".
- Under that, drag show [a warning] saying and type "Less than 5 hours' sleep. Please say what happened."
- From Do, drag hide into the "else" gap and pick "What happened overnight?".
- Click Preview, move the Sleep answer below 5, and check the question appears, is required and the warning shows. Move it back up and check the question disappears.
- Save the draft and publish.
The finished rule reads:
- when answers change
- if answer to Sleep < 5
- do: show What happened overnight?; make What happened overnight? required; show a warning saying "Less than 5 hours' sleep. Please say what happened."
- else: hide What happened overnight?
Example 2: a total score
Goal: add up three slider answers into a "Total" question.
- Add a Number question called "Total" to the form.
- On the Rules tab, drag when answers change onto the workspace.
- Drag set [Total] to into it.
- From Maths, put an add block into the "to" gap, and another add block inside it so there are three spaces.
- Fill each space with number from and pick each slider.
Example 3: stop a save that doesn't make sense
- Drag when the form is saved onto the workspace.
- Add if … do, with a condition such as answer to "Drinks today" > 30.
- In the "do" gap, add don't save, and say and type "That's more drinks than expected. Please check the number."
Example 4: open the right form next (workflow)
- On the workflow's Rules tab, choose On.
- Drag when [a form] is saved and pick "Morning check".
- Add if … do with "Morning check: Feeling unwell" is "Yes".
- In the "do" gap, add open "Symptoms" next.
Scheduled daily rules
A workflow rule that starts with every [day] at [time] runs once a day at that time, where the project is (using the project's time zone). It runs separately for each project that uses the workflow.
- Choose day, weekday, weekend day or a single day of the week.
- Type the time in 24-hour form, such as 17:00 or 08:30.
- If kep7 was restarting at the time, a missed rule still runs later that day.
A typical use is a daily check, such as: every day at 20:00, if entries of "Evening log" today by anyone = 0, email the project's owner "The evening log hasn't been filled in today."
Emails from rules
The email block sends an email. It sends only when a form is saved or when a scheduled rule runs, not while someone is still filling in a form.
Who it goes to
| Choice | Who gets it |
|---|---|
| the project's owner | The owner |
| the project's correctors | Every Corrector in the project |
| everyone in the project | All members |
| the person saving | Whoever saved the form |
| the group [name] | Everyone in one of your people groups |
What it can say
Type the subject and message in your own words. Text blocks and joins are fine, as are things like the person's name or the time.
For example, write "Sleep was low last night. Open kep7 to see the details." rather than trying to put the number in.
Email limits
- One rule run sends at most 3 emails.
- A project sends at most 50 rule emails a day.
Limits and checks
| Limit | Amount |
|---|---|
| Rules per form or workflow | 60 |
| Emails per rule run | 3 |
| Rule emails per project per day | 50 |
| Messages shown at once | 10 |
| Times "for each" repeats | 100 |
| Buttons offered by "offer a button" | 6 |
When you publish, kep7 checks the rules. If a rule names a question or form that is no longer there, it loads as "(removed) …" so you can see it. Publishing is refused until you pick another question or form, or remove that block. Other problems, such as an email block with nobody to send to, or a "when" block placed inside another rule, are listed in the "Can't publish yet:" box.