Skip to main content
This constraint can be used for three purposes, all related to which periods or shifts an employee should be considered available for:
  1. Mark an employee as strictly unavailable for specific periods or shifts.
  2. Mark an employee as available but undesirable for specific periods or shifts.
  3. Mark an employee as available and desirable for specific periods or shifts.

Constraint schema

employeeAvailabilityConstraint
object
Used to indicate when employees are strictly or preferably available or unavailable to work.

Strict unavailability

To define certain periods as strictly unavailable for an employee, simply specify the periods in the constraint. The solver will then never assign shifts to the employee during these periods.
The below constraint makes it strictly impossible for employee with id ‘employee-1’ to work on weekends.
{
  "id": "eac-weekends",
  "importance": "STRICT",
  "isDesired": false,
  "filters": {
    "employees": {
      "ids": ["employee-1"]
    }
  },
  "periods": {
    "labels": ["WEEKENDS"]
  }
}

Undesired availability

To mark that an employee would rather not work during certain periods, set the isDesired field to false and choose an importance level different than STRICT. The solver will try to avoid assigning shifts to the employee during these periods, but it is not strictly forbidden.
The below constraint makes it undesirable for employee with id ‘employee-1’ to work on Mondays or Thursdays.
{
  "id": "eac-undesired-mondays-thursdays",
  "importance": "HIGH",
  "isDesired": false,
  "filters": {
    "employees": {
      "ids": ["employee-1"]
    }
  },
  "periods": {
    "days": {
      "daysOfWeek": ["MON", "THU"]
    }
  }
}

Desired availability

To mark that an employee prefers working on certain periods or shifts, set the isDesired field to true and choose an importance level different than STRICT (STRICT is currently not supported on desired constraints).
The below constraint makes it preferred to assign shifts with shift label night to employee with id ‘employee-1’ on Mondays, Tuesdays or Wednesdays.
{
  "id": "eac-desired-night-shifts",
  "importance": "MEDIUM",
  "isDesired": true,
  "filters": {
    "employees": {
      "ids": ["employee-1"]
    },
    "shifts": {
      "labels": ["night"]
    }
  },
  "periods": {
    "days": {
      "daysOfWeek": ["MON", "TUE", "WED"]
    }
  }
}

Availability with work filters

You can also use work filters to target specific kinds of work. With role and workload filters, you can make the constraint apply only to work carried out in certain roles and with certain workload categories. It is also possible to apply role or workload filters separately.
The below constraint makes it undesirable for employee with id employee-1 to work shifts in role role-1 with workload category on_call on weekends. Work in other roles or with other workload categories is not targeted by this constraint.
{
  "id": "eac-undesired-weekend-role-1-oncall-workload",
  "importance": "HIGH",
  "isDesired": false,
  "filters": {
    "employees": {
      "ids": ["employee-1"]
    },
    "work": {
      "roles": {
        "ids": ["role_1"]
      },
      "workloads": {
        "categories": ["on_call"]
      }
    }
  },
  "periods": {
    "labels": ["WEEKENDS"]
  }
}