10.2.5.3. Creating a guided rule for no more than one shift per day
The OneEmployeeShiftPerDay guided rule creates a hard constraint that employees are not assigned more than one shift per day. In the employee rostering example, this constraint is created using the guided rule designer.
Procedure
-
In Business Central, go to Menu
Design Projects and click the project name. -
Click Add Asset
Guided Rule. -
Enter
OneEmployeeShiftPerDayas the Guided Rule name and select theemployeerostering.employeerosteringPackage. - Click Ok to create the rule asset.
-
Add a WHEN condition by clicking the
in the WHEN field.
- Select Free form DRL from the Add a condition to the rule window.
In the free form DRL box, type the following condition:
$shiftAssignment : ShiftAssignment( employee != null ) ShiftAssignment( this != $shiftAssignment , employee == $shiftAssignment.employee , shift.timeslot.startTime.toLocalDate() == $shiftAssignment.shift.timeslot.startTime.toLocalDate() )This condition states that a shift cannot be assigned to an employee that already has another shift assignment on the same day.
-
Add the THEN condition by clicking the
in the THEN field.
- Select Add free form DRL from the Add a new action window.
In the free form DRL box, type the following condition:
scoreHolder.addHardConstraintMatch(kcontext, -1);- Click Validate in the upper-right corner to check all rule conditions are valid. If the rule validation fails, address any problems described in the error message, review all components in the rule, and try again to validate the rule until the rule passes.
- Click Save to save the rule.
For more information about creating guided rules, see Designing a decision service using guided rules.