Create a rule for a calculated value

You can create a rule that enables the system to automatically calculate a value in a form. This allows you to automatically calculate certain values based on manually entered form data. reducing calculation errors and simplifying forms.

Want to see how to perform this task? Watch the video below.

You can also create rules that raise automatic queries or send an e-mail notification. See:

You must have a study version in the Testing container that includes the required elements. You access the Rules interface from a specific study version and site as described in Access the rules interface.
  1. Navigate to your desired study in Testing mode and select a site (if you have access to multiple sites).
  2. In the table, locate and click the visit card that you want to edit.
  3. On the left, click the form for which you want to create the rule.
  4. Select the question that should contain a rule and where the calculated value should display.
  5. On the right, expand the Rules pane, and click Add Rules.
  6. In the Rule editor complete the following fields. Then click Next.
    Field Description
    Rule Name

    Enter a name for your rule. Each name must be unique within a study and its number of characters should not exceed 512.

    Description

    Enter a short description of your rule that doesn't exceed 4000 characters.

    This field isn't mandatory. However, adding a description can help you distinguish between each rule and its purpose in a study. This is helpful when you want to reuse a rule.

    Unblock Form

    Turn this toggle on if you want to allow site users to edit and save forms without being blocked while the rule is running.

    Note:

    Complex rules take more time to run. Site users can still enter values and save the form while the rule is running. However, form updates generated by complex rules can be delayed and may only appear after a page refresh.
  7. In the Variable section, Define rule variables.
  8. In the Expression section, enter the JavaScript expression that will be evaluated to a value.

    For example, to calculate BMI:

    return weight/(height*height);

    Note:

    By default, the rule will run against every visit in the study that contains the form and in all study versions.

    Tip:

    A predictive text feature is available as you type, with available Subject attributes, rule helper functions, and more. See Use predictive text to write rules.
  9. From the Action drop-down, choose Calculate Value.
    This allows the system to automatically calculate a value and populate a read-only item with the result. You must also

    Note:

    If the rule expression contains syntax errors the Rule Editor marks them for you to correct.
  10. Select the Answer Type from nthe dropdown:
    • Number
    • Text
    • Choice
  11. If your answer type is Number, select the Data Format for the calculated value.
    For example, you can calculate the Body Mass Index (BMI) based on a subject's height and weight and set the format to one decimal point as "1.0".
  12. Click Save.
Your rule is now created and in Draft status.
To make your rule available in production. You must test, approve, and publish your rule. Rules are study version independent and will apply in every mode once they reach the Published state.

If you want to delete this rule and start over, click the menu icon (Rules menu icon), select Delete.

For examples, and more information on developing custom rules, see: