Introduction to Rules
While Functions are the building blocks of the SimplyWork platform, Rules are the brains. Rules use functions to make decisions on data.
For example, in a Data Import or Data Export rules are used to parse the data and convert into a suitable format to be saved or transmitted (e.g. converting a date format from "03/26/2022" to "2022-03-22").
In the case of managing employee time, rules are used to perform all logical calculations such as rounding punches, calculating overtime, determining when a legislative law has been violated (e.g. California Meal Break) or awarding a shift premium.
Rules are also present in workflows throughout the SimplyWork platform, deciding when a document should go from point A to point B or C in your business processes.
Before jumping into specifics, a few hi-level concepts to be reviewed including Writing Editor and the Rule Types, Rule States and Parameters.
Writing Rules
The concept of writing rules is implemented in one of two ways:
- Stored rules to be applied by calculation engines
- Applied rules which are attached to processes
Stored Rules
Stored rules are ones which are used by a calculation engine such as Time and Scheduling. In these cases, we write rules such as rounding, attendance and overtime and attach them to a Pay Group. Next, when a workflow triggers the time calculation engine (or just "rules engine"), to process, it loads the rules assigned to the worker by their associated Pay Group and executes. In this way the rules are written and stored as a collection of rule statements to be applied by the relevant calculation engine.
With stored rules, you use a combination of IF, SET and DO operations (covered in the next section) to make decisions about the workflow of the rule, when to get stop and get out, and what to do at the end. Stored rules have the added benefit of creating temporary variables to store values while working through a rule sequence.
Applied Rules
Applied rules live within a host application, such as Data Imports, Data Exports or Forms. Rather than making logic decisions with the IF operator, applied rules always employe the SET operator, meaning they are processing data and assigning to something else, as as when importing a file from a remote system, cleaning up the values, and storing in SimplyWork.
As we'll see in the next sections, the interface used to create and edit these rules is the same, so the above is not something you need to manage, just understanding the slight differences in application.
Rule Types
When creating rules you must specify the scope, or context, of the rule which is called the Rule Type. This tells what form of data to expect. Types include:
- Time
- Schedule
- Punch
- Transaction
When rules are used with Data Imports, Exports, Workflows and other areas of the system, the Rule Type is dynamically determined based on the data being processed. When creating Stored Rules to go into a Pay Group and be part of a time or schedule calculation, the type is set to Time
.
Rule States
Rules also use States to determine when/where in the lifecycle of a document getting updated that the rule should be processed. In the case of the Rule Type Time
the states determine when during the processing of a time punch the rule should be invoked, and are outlined in the following table.
State | Description |
---|---|
Initialization | General initialization of global variables which may be used by other rules |
Before Punch | Before loading a punch; is repeated on each subsequent punch |
After Punch | After loading a punch but before hours could be calculated; is repeated on each subsequent punch |
After Segment | Rule is processed at the end of a work segment, meaning any OUT type activity (Start Lunch, OUT) where paid time can be measured; in a typical day, might be repeated twice |
After Shift | Rule is processed at the end of a shift, considering there could be multiple shifts in the say work day |
After Day | Rule is processed at the end of the work day |
After Week | Rule is processed at the end of the week |
The following diagram demonstrates where rules would be executed in a time calculation timeline:
Rule Parameters
Rule Parameters are any pre-defined variables which will be part of rule execution, but are overridden by the user. For example, in writing a rounding rule, the logic is always the same, but the number of minutes to which someone desires to round will vary (e.g. 1, 6, 15?). A Rule Parameter is used to represent the choice for number of minutes, and can have a declared default value, but is intended to be overridden when the rule is actually applied to a Pay Group. This facilitates creating rules which are reusable.