# Creating a Survey-Based Notification Rule Template

This rule template allows you to configure notifications to be sent when specific conditions are met. The system sends rule-based notifications to site users immediately. It does not include these notifications in the site email digest.

## Prerequisites

* Ensure that all survey names, schedule names, event names, group type names, and group name fields are named correctly.
* Ensure that the survey and schedule are already created. See <a href="/en/lr/912957/">Configuring Surveys</a> for more information.

## Create a Rule Template

Complete the following steps to create a rule template: 

{:start="1"}
1. In eCOA Studio, open the **Rules** tab.
2. Select **Create Rule**.
3. In the Rule Templates dialog box, select **Survey-based Notification** and select **Select Template**. A new rule template for survey-based notifications opens.
4. Enter a name for the rule in the Name field. For example: Rule_1
5. Enter a description of what the rule is for in the Description field to help other Studio users identify what the rule is when they see it in the Rules tab. For example: This rule enables you to receive notifications when a user answers certain questions on a survey.
6. Create a reference for the survey or survey part that should trigger the rule evaluation.  A rule triggered by a specific part can only reference data from that part. When the reference survey conditions are met, the system will automatically evaluate the expression provided in the rule template. For example: `$survey.hads.[*].[*].[*]` See <a href="/en/lr/918791/#creating-a-reference">Creating a Reference</a> on the Understanding Rules page for more information.<br><br>You cannot use instance ranges (e.g., [1:5]) or instance lists (e.g., [1;3;5]) when defining a Survey Reference trigger. You must use a single instance.

<div class="note-border alert-tip">
  <div class="alert alert-tip" role="alert">
    <div><i class="far fa-lightbulb"></i></div>
    <div class="alert-text">
      <p><strong>Tip</strong>: Enter $ or @ to begin, and then select from the options that are displayed. Use the $survey identifier to reference a survey where all parts are complete or missed. Use the $surveyPart identifier to reference a specific completed part, even if other parts are incomplete. After you select each option, enter a period and select from the next list of options that are displayed.</p>
    </div>
  </div>
</div>



{:start="7"}
1. Optionally, define the precondition using references or variables, and add the data you want to evaluate. For example: `@survey.hads.[*].[*].[-1].status = "COMPLIANT" `- In this example, adding the following precondition ensures that a rule only runs when the most recent submitted survey is compliant. See <a href="/en/lr/918791/#creating-a-reference">Creating a Reference</a> and <a href="/en/lr/918791/#creating-a-variable">Creating a Variable</a> on the Understanding Rules page for more information.


<div class="note-border alert-info">
  <div class="alert alert-info" role="alert">
    <div><i class="far fa-info-circle"></i></div>
    <div class="alert-text">
      <p><strong>Note</strong>:</p>
<ul>
  <li>The system will not evaluate the rule expression unless the defined conditions are true.</li>
  <li>If you reference Status, Datetime, Block, or Timezone data in a survey with parts, you must specify the part in the reference. You do not need to specify a part to reference a Score.</li>
</ul>
    </div>
  </div>
</div>



{:start="8"}
8. Using Vault expression engine syntax, create an expression that evaluates to TRUE or FALSE. Only references that evaluate to TRUE will cause the action to run. See Creating an Expression for more information. For example: `IF((Q1ANS = "3") || (Q2ANS = "3"), true, false)`

<div class="note-border alert-info">
  <div class="alert alert-info" role="alert">
    <div><i class="far fa-info-circle"></i></div>
    <div class="alert-text">
      <p><strong>Note</strong>: In the example above, the Q1ANS variable will check whether the first question, HADS0101, is <strong>Most of the time</strong> (answer name 3), OR it will use the Q1ANS variable to check whether the answer to the second question, HADS0102, is <strong>Hardly at all</strong> (answer name 3). If either of those are true, then the expression will evaluate as true.</p>
    </div>
  </div>
</div>

 

{:start="9"}
9. Enter a name in the Notification Name field. Example: hads_notification_1
10. Select **Site Staff** or **Email Address** from the recipient list. If you selected Site Staff, continue to Step 11. If you selected Email Address, skip to Step 12.
11. Select all roles you want to receive the notification from the Role Type list. Skip to Step 14.
12. In the Email Address(es) field, enter the email address of a person you want to receive notifications, and press **ENTER**. You can add multiple emails.<br>

<div class="note-border alert-tip">
  <div class="alert alert-tip" role="alert">
    <div><i class="far fa-lightbulb"></i></div>
    <div class="alert-text">
      <p><strong>Tip</strong>: As a best practice Veeva recommends using listserv email addresses instead of individual emails so you can update email recipients without creating a new collection version.</p>
    </div>
  </div>
</div>



{:start="13"}
1.  In the Testing Email field, enter the email address you want to use during UAT. When in UAT, this email address will receive any rule-triggered emails instead of the addresses listed in the Email field. For example: test.person@veeva.com

<div class="note-border alert-info">
  <div class="alert alert-info" role="alert">
    <div><i class="far fa-info-circle"></i></div>
    <div class="alert-text">
      <p><strong>Note</strong>: You can add tokens to include study-specific information in the title and body of the notification or email. See the <a href="#using-available-tokens">Using Available Tokens</a> section for more information.</p>
    </div>
  </div>
</div>



{:start="14"}
14.    Enter the title you want to be displayed with the notification in the Title field. For example: `<b>Survey answer exceeds threshold for {{studyName}}</b>`
15.    Enter the body message of the notification in the Body field. For example: `The HADS response for  <b>{{participantID}}</b> in <u>{{studyName}}</u> has answered a question with a response that requires additional attention.  See <a href="https://www.Veeva.com">Veeva.com</a> for more information.`
16.   To prevent users who do not have permission from seeing restricted data, select the **Yes** option under Restricted Data. 

<div class="note-border alert-info">
  <div class="alert alert-info" role="alert">
    <div><i class="far fa-info-circle"></i></div>
    <div class="alert-text">
      <p><strong>Note</strong>: If any of the surveys referenced in the rule collect restricted data, the <strong>Yes</strong> option is automatically selected. If a referenced survey is later updated to be restricted, the restricted value here is automatically updated too. This setting is inactive if no restricted surveys are referenced in a rule template.</p>
    </div>
  </div>
</div>



{:start="17"}
17. Select **Save**.
18. Select **Add Another** and repeat Steps 9 through 17 to add additional notifications.
19. Select **Save & Exit**.

## Using Available Tokens
Use these tokens to add dynamic information about what information triggered the notification:

<table>
  <tr>
   <td><strong>Information Type</strong>
   </td>
   <td><strong>Description</strong>
   </td>
   <td><strong>Token</strong>
   </td>
  </tr>
  <tr>
   <td>Participant ID
   </td>
   <td>The ID of the participant who completed the survey.
   </td>
   <td>{{participantID}}
   </td>
  </tr>
  <tr>
   <td>Participant ID (Linked)
   </td>
   <td>
<ul>

<li>The ID of the participant who completed the survey.</li>

<li>Linked to the participant profile. </li>

<li>Can only be used in the notification body.</li>

<li>Must use three curly braces for the hyperlink to be displayed correctly.</li>
</ul>
   </td>
   <td>{{{participantIDLink}}}
   </td>
  </tr>
  <tr>
   <td>Site ID
   </td>
   <td>The study site number.
   </td>
   <td>{{siteID}}
   </td>
  </tr>
  <tr>
   <td>Site Name
   </td>
   <td>The study site name.
   </td>
   <td>{{siteName}}
   </td>
  </tr>
  <tr>
   <td>Study Name
   </td>
   <td>The study name.
   </td>
   <td>{{studyName}}
   </td>
  </tr>
  <tr>
   <td>Survey Label
   </td>
   <td>
<ul>

<li>The survey label for the survey.</li>

<li>If available, the translated value is displayed for site notifications. Dynamic information cannot be translated for email notifications, so they are displayed in English.</li>
</ul>
   </td>
   <td>{{surveyLabel}}
   </td>
  </tr>
  <tr>
   <td>Survey Label (Linked)
   </td>
   <td>
<ul>

<li>The survey label for the survey.</li>

<li>Linked to the completed triggering survey.</li>

<li>Can only be used in the notification body.</li>

<li>If available, the translated value is displayed for site notifications. Dynamic information cannot be translated for email notifications, so they are displayed in English.</li>

<li>Must use three curly braces for the hyperlink to be displayed correctly. </li>
</ul>
   </td>
   <td>{{{surveyLabelLink}}}
   </td>
  </tr>
  <tr>
   <td>Survey Schedule
   </td>
   <td>The schedule name for the survey.
   </td>
   <td>{{surveySchedule}}
   </td>
  </tr>
</table>

### Adding a Token

1. Select the **Tools** button.
2. Select the **Template Tokens** tab.
3. Select **Copy** <i class="far fa-clone"></i> next to the token. The text is copied to your clipboard.
4. Paste the token into the Title or Body field.

The token is added to the title or body where you pasted it.

## Working with Rules
<div class="note-border alert-info">
  <div class="alert alert-info" role="alert">
    <div><i class="far fa-info-circle"></i></div>
    <div class="alert-text">
      <p><strong>Note</strong>:  To maintain regulatory compliance, the system automatically logs a system-provided reason for change in the audit trail whenever a user creates, updates, or deletes a rule.</p>
    </div>
  </div>
</div>



### Saving a Rule

Draft template changes are automatically saved as you make updates. If you sign out and back in, when you access the templates, you can continue working on your draft. If you choose to create a new draft before manually saving an in-progress draft, your changes will be lost. 

You can save a rule by selecting the **Save** button.

### Editing a Rule

You can edit a rule when the collection is in a Draft state.

Complete the following steps to edit a rule:

1. Open the collection, select the **Rules** tab, and select the **Edit Rule** icon (<img class="inline" src="https://platform.veevavault.help/assets/images/23r2_ePRO_edit_button.png" alt="Edit Rule icon" style="" />) next to the rules you want to edit.
2. Make any changes you want to see, and select **Save**. Your changes are saved.

### Deleting a Rule

You can only delete rules that have not been included in an approved collection. Once a rule is deleted, it cannot be recovered.

Complete the following steps to delete a rule:

1. Open the collection, select the **Rules** tab, and select the **Delete Rule** icon (<img class="inline" src="https://platform.veevavault.help/assets/images/24r2_delete_icon.png" alt="Delete icon" style="" />) next to the rule you want to delete. A confirmation box opens.
2. Select **Delete**. The rule is deleted.