Logic
This topic describes how to supply the "Logic" settings of a script-based alert definition.
The Alert Script Logic section also includes a field to enter an expression to determine the priority of the alert. When the expression in the Alert Active Logic field returns a boolean true, the alerts engine generates an alert. In addition to the operators, there are four script functions we can use:
- abs() - Specify the absolute value of a number
abs(n)
- if() - Set up conditional logic using three parameters
if(condition,true_value,false_value)
- str() - Convert a number to a string
str(n)
- sum() - Sums one or two parameters, such as sum(x) or sum(x,y).
The expressions entered here are evaluated using the Java Mathematical Expression Parser (JEP) API. This API accepts expressions as text strings and evaluates them. These expressions follow the basic rules for mathematical expressions. They can contain arithmetic functions, boolean expressions, predefined constants such as "pi", and supports using strings, complex numbers and Vectors. Use parentheses to control the order of precedence in calculations.
The Alert Priority Logic field also accepts JEP expressions. The only meaningful values for this field are the numbers 1, 2, and 3. Consequently, the expressions used in this field should produce any one of these values. The simplest useful expression is just the number 1, for example. It may be desirable, however, to use more complex logic to determine the priority of the alert. For example, if an alert is generated when a data value is "out of range", the priority could be calculated based on how far "out of range" the data is. The further the data is away from its target value, the higher the priority.
Note that The values 1, 2, and 3 correspond to priorities of High, Normal, and Low in the My Alerts portlet.
Here are some examples of JEP expressions that can be used in the Alert Active Logic field.
This expression returns true when the value of the GrossSales parameter is less than the Costs parameter:
( GrossSales - Costs ) <= 0
This expression could be used to generate an alert when profits are less than zero.
This expression returns true when the difference between the GrossSales parameter and the Costs parameter is less than a threshold parameter called MinProfitMargin:
( GrossSales - Costs ) <= MinProfitMargin This expression could be used to generate an alert when profits are below a predetermined threshold value.
Note that Thresholds can be configured to allow users to choose their own values.
Here is an example of a JEP expression that can be used in the Alert Priority Logic field. This expression returns a 1 if the actual profit margin is less than half of the threshold called MinProfitMargin; otherwise it returns a 2:
if((GrossSales - Costs ) <= MinProfitMargin * .5),1,2)
This expression is useful for adjusting the priority of an alert based on how great the variance between actual sales and the target threshold is. Parent topic: Script-based alert definitions
Related tasks
Editing the example script-based alert definition
Library | Support | Terms of use |
Last updated: Thursday, March 15, 2007 11:57am EST
This information center is powered by Eclipse technology. (http://www.eclipse.org)