This article will explain the principles and the functions of the rules engine.
Triggers
Firstly a rule has to start with some sort of trigger. A trigger can be time based or event based. A rule can only have one trigger attached at the same time.
Here is the triggers available for a rule.
The Record Trigger
The Record trigger is used for event based triggers. This function is triggered by an event in a data table such as a part count or a downtime event.
Name: Here we can give a name to this function.
Description: Optional extra space for the function.
Data Model: This is where we choose the table the function should read for triggering.
Run after record is created: When this is chosen a rule will be triggered as soon as a new entry comes into the table.
Run after record is updated: Rule will be triggered when an existing entry is updated.
Run after record is deleted: Rule will be triggered when an existing entry is deleted.
Listen for API/Pre-Processor publishes insead of Data-Modeller publishes: This should always be checked. When left unchecked the rule will not react to Sensorbot data.
The Schedule Trigger
The schedule trigger is used to trigger a rule on a timed basis. Chose the time basis for triggering the rule here.
Functions
After a trigger is chosen we can start building the functions of the rule. Here is the list of functions available. We will go through each of these to explain the function.
There are two type of functions: Logical functions and Output Functions
Logical Functions:
The Get Record(s):
This function is used to grab information from the data tables.
Name: Here we can give a name to this function. If using more than one getRecords function in a rule make sure to give each function a unique name.
Description: Optional extra space for the function.
Data Model: This is where we choose the table the function should read for triggering. In this example we have chosen to get records from the downtime table.
Filter:
We can filter the results of the function by any of these fields.
The Modify:
This function allows the modification of a variable in the rule.
Field: This is where we choose the variable to be modified.
The next box is where we set up the modification. Using :F will provide a list of functions. Using :V will provide a list of rule variables.
The Decide:
This function provides a way to set up IF statements.
Name: Here we can give a name to this function.
Description: Optional extra space for the function.
Outcomes: These are the various if statements. Dropdown provides a list of statements in the function or allows adding a new statement.
The next box is where the statement is created.
The Pause:
This function stops the execution of the rule for a given amount of time.
Name: Here we can give a name to this function.
Description: Optional extra space for the function.
Time unit: Choose the unit of time.
Duration: Time value of the pause.
The Create Variable:
This function provides a way to add extra variables to the rule.
Name: Here we can give a name to this function.
Description: Optional extra space for the function.
Variable Name: Give the variable a name.
Variable Type: Choose the type of data the variable will hold.
Set default value: Optional box to give the variable a default value.
The Loop:
This function loops through records retrieved from a previous function.
Name: Here we can give a name to this function.
Description: Optional extra space for the function.
Loop Through: This is where we choose the function that has a list of data.
Output Functions:
Send Emails:
This provides a way to send emails from a rule. Useful for setting up notifications when data doesn't meet expectations.
The Create Record:
This will create a new record in a data table.
Name: Here we can give a name to this function.
Description: Optional extra space for the function.
Data Model: The data table one wishes to add a new record to.
The next fields depends on the table. This table only has one field named test to insert any data into.
The Update Record:
This provides a way to update a record in a table.
The Delete Record:
This provides a way to delete a record from a table.
The Send Form Data:
This provides a way to make API calls. This is used to send or receive data from API endpoints. This function can store API data into a table for later retrieval.