15.2. Define a Template

  1. Ensure that you are at the DataHub Properties Notification Configuration and that you have already configured a Notifier.

  2. In Notification Templates click the Add button to open the Configure Template window.

  3. For the Label, enter a name for this template, like TestAction.

  4. For Type, choose Stateful. (Please see the Notification Type reference for information on this and other options.)

  5. Click the Add button to add a new variable definition.

    Enter the name Input for the Variable Name, and ensure that both the Is Trigger box is checked and the Type is set to Point.

  6. Click the OK button to save the variable.

Now you are ready to create a state with a couple of corresponding scripts.

  1. In the Notification Templates list, highlight the TestAction you just created, and click the Edit button to reopen the Configure Template window.

  2. In States, click the Add button to create a new state.

  3. Down below, in State Properties, Settings, change the name from NewState to Low.

  4. In Scripts, Entry condition

    click the button with the three dots to open the Edit Script window:

    [Note]

    The scripting language is S-Sharp, which is documented here.

  5. Enter the formula: Input.DblVal < 50. Notice that the Input variable is listed in the right-hand panel. Also in that panel are the attributes of DataHub points. Since your Input variable is a DataHub point, you have access to those variables. In this case, for example, Input.DblVal is the value of the point, as a double.

  6. Click the OK button to save the script.

  7. Again in Scripts, click the 3-dots button for the OnEntry script.

  8. Create an on-entry script by entering the following in the script composition area:

     var subject = Input.Name + " is low.";
     var body = Input.Name + " = " + Input.DblVal;
     Emailer.Send(null,"[email protected]",subject,body);
    					

    This script will send an email to [email protected] with the subject line stating that the value of whatever DataHub point gets assigned to this template is low, and containing a single line showing the name and value of that point. The formula for the Emailer.Send function can be found in the Common Formulas panel of the Edit Script window, under Notifiers.

  9. Click the OK button to save the script. You are now ready to bind a variable.