Skip to main content
function preferRole(roleId, opts?): RuleEntry<"role-preference", object & EntityOnlyRuleOptions>;
Steer a multi-role member toward shifts tagged with a specific role.

Parameters

roleId
string
required
The role to prefer

Returns

RuleEntry<"role-preference", object & EntityOnlyRuleOptions> Penalizes assignment to shift patterns whose roleIds do not include the preferred role. The member is still assigned to other roles when coverage requires it; the penalty only matters when the solver has a choice. Shift patterns without any roleIds (open to all) are also penalized since they are not explicitly tagged with the preferred role. The targeted members must actually hold the preferred role in their roleIds. If none of them do, compilation reports an error because the rule would silently penalize all their assignments (the opposite of the intent). Typical use case: a waiter who can cover kitchen pass shifts in a pinch. Give the member both roles (roleIds: ["waiter", "pass"]) and use preferRole("waiter", ...) so the solver keeps them on the floor unless the pass team is short-staffed.