Este conteúdo não está disponível no idioma selecionado.
Chapter 6. Create rules for employee rostering using guided rules
You can create rules that define hard and soft constraints for employee rostering using the guided rules designer in Business Central.
6.1. Guided rules Copiar o linkLink copiado para a área de transferência!
Guided rules are business rules that you create in a UI-based guided rules designer in Business Central that leads you through the rule-creation process. The guided rules designer provides fields and options for acceptable input based on the data objects for the rule being defined. The guided rules that you define are compiled into Drools Rule Language (DRL) rules as with all other rule assets.
All data objects related to a guided rule must be in the same project package as the guided rule. Assets in the same package are imported by default. After you create the necessary data objects and the guided rule, you can use the Data Objects tab of the guided rules designer to verify that all required data objects are listed or to import other existing data objects by adding a New item.
6.2. Create a guided rule to balance employee shift numbers Copiar o linkLink copiado para a área de transferência!
The BalanceEmployeesShiftNumber guided rule creates a soft constraint that ensures shifts are assigned to employees in a way that is balanced as evenly as possible. It does this by creating a score penalty that increases when shift distribution is less even. The score formula, implemented by the rule, incentivizes the Solver to distribute shifts in a more balanced way.
Procedure
-
Go to Menu
Design Projects and click the project name. -
Click Add Asset
Guided Rule. -
Enter
BalanceEmployeesShiftNumberas 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
Employeein the Add a condition to the rule window. Click +Ok. -
Click on the
Employeecondition to modify the constraints and add the variable name$employee. Add the WHEN condition
From Accumulate.-
Above the
From Accumulatecondition, click click to add pattern and selectNumberas the fact type from the drop-down list. -
Add the variable name
$shiftCountto theNumbercondition. -
Below the
From Accumulatecondition, click click to add pattern and select theShiftAssignmentfact type from the drop-down list. -
Add the variable name
$shiftAssignmentto theShiftAssignmentfact type. -
Click on the
ShiftAssignmentcondition again and from the Add a restriction on a field drop-down list, selectemployee. -
Select
equal tofrom the drop-down list next to theemployeeconstraint. -
Click the
icon next to the drop-down button to add a variable, and click Bound variable in the Field value window.
-
Select
$employeefrom the drop-down list. -
In the Function box type
count($shiftAssignment).
-
Above the
-
Add the THEN condition by clicking the
in the THEN field.
Select
Modify Soft Scorein the Add a new action window. Click +Ok.-
Type the following expression into the box:
-($shiftCount.intValue()*$shiftCount.intValue())
-
Type the following expression into the box:
- 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.
6.3. Create a guided rule for no more than one shift per day Copiar o linkLink copiado para a área de transferência!
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
-
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() )
$shiftAssignment : ShiftAssignment( employee != null ) ShiftAssignment( this != $shiftAssignment , employee == $shiftAssignment.employee , shift.timeslot.startTime.toLocalDate() == $shiftAssignment.shift.timeslot.startTime.toLocalDate() )Copy to Clipboard Copied! Toggle word wrap Toggle overflow 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);
scoreHolder.addHardConstraintMatch(kcontext, -1);Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 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.
6.4. Create a guided rule to match skills to shift requirements Copiar o linkLink copiado para a área de transferência!
The ShiftReqiredSkillsAreMet guided rule creates a hard constraint that ensures all shifts are assigned an employee with the correct set of skills. In the employee rostering example, this constraint is created using the guided rule designer.
Procedure
-
Go to Menu
Design Projects and click the project name. -
Click Add Asset
Guided Rule. -
Enter
ShiftReqiredSkillsAreMetas 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
ShiftAssignmentin the Add a condition to the rule window. Click +Ok. -
Click on the
ShiftAssignmentcondition, and selectemployeefrom the Add a restriction on a field drop-down list. -
In the designer, click the drop-down list next to
employeeand selectis not null. Click on the
ShiftAssignmentcondition, and click Expression editor.-
In the designer, click
[not bound]to open the Expression editor, and bind the expression to the variable$requiredSkill. Click Set. -
In the designer, next to
$requiredSkill, selectshiftfrom the first drop-down list, thenrequiredSkillfrom the next drop-down list.
-
In the designer, click
Click on the
ShiftAssignmentcondition, and click Expression editor.-
In the designer, next to
[not bound], selectemployeefrom the first drop-down list, thenskillsfrom the next drop-down list. -
Leave the next drop-down list as
Choose. -
In the next drop-down box, change
please choosetoexcludes. -
Click the
icon next to excludes, and in the Field value window, click the New formula button. -
Type
$requiredSkillinto the formula box.
-
In the designer, next to
-
Add the THEN condition by clicking the
in the THEN field.
-
Select
Modify Hard Scorein the Add a new action window. Click +Ok. -
Type
-1into the score actions box. - 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.
6.5. Create a guided rule to manage day off requests Copiar o linkLink copiado para a área de transferência!
The DayOffRequest guided rule creates a soft constraint that allows a shift to be reassigned to another employee in the event the employee who was originally assigned the shift is no longer able to work that day. In the employee rostering example, this constraint is created using the guided rule designer.
Procedure
-
Go to Menu
Design Projects and click the project name. -
Click Add Asset
Guided Rule. -
Enter
DayOffRequestas 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:
$dayOffRequest : DayOffRequest( ) ShiftAssignment( employee == $dayOffRequest.employee , shift.timeslot.startTime.toLocalDate() == $dayOffRequest.date )
$dayOffRequest : DayOffRequest( ) ShiftAssignment( employee == $dayOffRequest.employee , shift.timeslot.startTime.toLocalDate() == $dayOffRequest.date )Copy to Clipboard Copied! Toggle word wrap Toggle overflow This condition states if a shift is assigned to an employee who has made a day off request, the employee can be unassigned the shift on that 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.addSoftConstraintMatch(kcontext, -100);
scoreHolder.addSoftConstraintMatch(kcontext, -100);Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 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.