Create a rule for an automated query

You can create a rule that generates an automated query if the value entered by the site does not meet the acceptance criteria defined by the rule logic. The query message lets users know they should verify their entry and correct any errors.

Note:

If the rule to create automated queries is published for all data, all published rules will be re-run against all data in the study. Meaning that all queries in that study that were previously closed by an user without data update, will be re-opened.

To avoid this, make sure you publish the rule for future data only. For more information see Publish a single rule.

If a rule that triggers an assigned query is updated to add a new role in the assignment list, then this update will only become available when a new query is created. Existing open queries will not be impacted and they will not become assigned to the new role you add in the assignment list. If a query is closed and re-opened, that query becomes visible to the newly added roles.

You can also create a rule that calculates a value for use in a form or sends 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 the rule and to which the query will be raised upon if applicable.
  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 raise a query.

    For example:

    if (diastolic>systolic){
        return false;        //query is raised when return false condition is met
    } 
    else{    
        return true;
    }

    Note:

    • If the action item is dynamic the rule expression should include logic to ensure the item is visible before the query is triggered.
    • 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 select the query type you want.
  10. Enter a query message in the appropriate text-box.
    Both query types require you to add a query message.
  11. 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: