Skip to main content
Assignment rules automatically route tickets to the right agents based on conditions like ticket type, priority, customer, or custom fields. This ensures tickets reach qualified agents quickly without manual intervention.

Understanding Assignment Rules

Assignment rules in Frappe Helpdesk:
  • Automatically assign tickets to agents or teams based on conditions
  • Balance workload across team members
  • Route by expertise to ensure proper skill matching
  • Operate in priority order when multiple rules match
  • Support scheduling for time-based assignments

Assignment Rule Components

Based on the Assignment Rule doctype and implementation:

Basic Settings

  • Rule Name: Descriptive identifier
  • Description: Purpose and scope of the rule
  • Priority: Order of evaluation (higher priority = evaluated first)
  • Disabled: Toggle to deactivate without deleting

Assignment Conditions

  • Assign Condition: When to assign tickets (JSON or Python expression)
  • Unassign Condition: When to remove assignments
  • Document Type: Always “HD Ticket” for Frappe Helpdesk

Assignees

  • Users: List of agents who can receive assignments
  • Assignment Strategy: How to distribute tickets among users

Creating Assignment Rules

1

Navigate to Assignment Rules

Go to Settings > Assignment Rules in the agent interface.
2

Create New Rule

Click “New Assignment Rule” and configure:
  • Name: e.g., “Bug Reports to QA Team”, “VIP Customers to Senior Agents”
  • Description: Brief explanation of what this rule handles
  • Priority: Higher number = evaluated first (use 1-10 range)
  • Document Type: HD Ticket (pre-selected)
3

Define Assignment Conditions

Specify when this rule should assign tickets:Using Portal View (Recommended):
  • Use the visual condition builder in the portal
  • Automatically generates JSON format
  • Easier for non-technical users
Using JSON Format:
[["ticket_type", "==", "Bug"], ["priority", "==", "High"]]
Using Python Expression:
doc.ticket_type == 'Bug' and doc.priority == 'High'
4

Add Assignees

In the Assignment Rule User table, add agents:
  1. Click “Add Row”
  2. Search for agent by name or email
  3. Add multiple agents for round-robin distribution
  4. Order matters: first agent receives first matching ticket
5

Configure Assignment Strategy

Choose how tickets are distributed:
  • Round Robin: Rotate assignments evenly among all users
  • Load Balancing: Assign to user with fewest open tickets
  • Based on Field: Use a ticket field to determine assignee
6

Set Unassign Conditions (Optional)

Define when to automatically remove assignments:
[["status", "==", "Closed"]]
This helps keep agent workload counts accurate.
7

Save and Test

Save the rule and create test tickets to verify it works as expected.
Assignment rules are evaluated in priority order. If multiple rules match, the highest priority rule is applied. Implementation: helpdesk/api/assignment_rule.py:5-29

Assignment Conditions

Condition Format

Conditions can be specified in two formats: JSON Format (Portal-Generated):
// Single condition
[["status", "==", "Open"]]

// Multiple conditions (AND)
[
  ["ticket_type", "==", "Bug"],
  ["priority", "in", ["High", "Urgent"]]
]

// Complex conditions
[
  ["agent_group", "==", "Support Team"],
  ["customer", "!=", null]
]
Python Expression:
# Simple condition
doc.status == 'Open'

# Complex logic
doc.ticket_type == 'Bug' and doc.priority == 'High' and doc.customer == 'Enterprise Corp'

# Using helper functions
is_business_hours() and doc.priority == 'Urgent'

Available Fields

You can use any field from the HD Ticket doctype:
  • subject, description
  • status, priority, ticket_type
  • agent_group, raised_by, customer
  • via_customer_portal, is_first_ticket
  • sla, template
  • Custom fields you’ve added

Condition Validation

The system validates conditions on save (see helpdesk/extends/assignment_rule.py:15-30):
  • JSON format must be valid
  • Python expressions must be syntactically correct
  • Use the portal view to avoid syntax errors
Invalid conditions will prevent the assignment rule from being saved. Always test conditions with sample tickets.

Assignment Strategies

Round Robin

Distributes tickets evenly across all users in the assignment list:
  1. First ticket → First user
  2. Second ticket → Second user
  3. Last ticket → Last user
  4. Next ticket → Back to first user
Best for: Teams with similar skill levels handling similar ticket types

Load Balancing

Assigns tickets to the agent with the fewest currently open tickets:
  • Counts open tickets assigned to each user
  • Assigns to user with lowest count
  • Helps prevent agent overload
Best for: Teams with varying ticket complexity or agent availability

Based on Field

Uses a ticket field value to determine the assignee:
  • Match agent based on ticket property
  • Useful for territory, product, or customer-based routing
  • Requires field to contain agent ID or email
Best for: Specialized assignments based on expertise or responsibility

Agent Groups and Teams

Assignment rules work in conjunction with agent groups:

Team-Based Assignment

1

Create Agent Groups

Define teams in Settings > Teams:
  • Support Team
  • QA Team
  • Billing Team
  • Technical Team
2

Assign Agents to Groups

Add team members to each group with their roles.
3

Create Group-Specific Rules

Make assignment rules that route to team members:Condition:
[["agent_group", "==", "QA Team"]]
Assignees: Add all QA Team members

Restricting by Agent Group

In HD Settings, you can configure:
  • Restrict Tickets by Agent Group: Agents only see tickets for their groups
  • Assign Within Team: Ensure tickets stay within assigned team
  • Do Not Restrict Tickets Without Group: Allow flexible handling of ungrouped tickets
See hd_settings.json:11-15 for these configuration options.

Assignment Scheduling

Route tickets based on time of day or day of week:

Time-Based Rules

1

Define Shift Schedules

Create assignment rules for different shifts:
  • Morning shift (8 AM - 4 PM)
  • Evening shift (4 PM - 12 AM)
  • Night shift (12 AM - 8 AM)
2

Use Time Conditions

Add time-based conditions:
from frappe.utils import now_datetime
hour = now_datetime().hour
8 <= hour < 16  # Morning shift
3

Set Priority

Give time-based rules higher priority than general rules to ensure they’re evaluated first.

Weekend and Holiday Routing

# Weekend condition
from frappe.utils import now_datetime
now_datetime().weekday() in [5, 6]  # Saturday, Sunday

# Holiday condition
from frappe.utils import is_holiday
is_holiday(doc.sla.holiday_list)

Priority and Rule Order

Assignment rules are evaluated in priority order:

Priority Best Practices

  1. Highest Priority (9-10): Urgent or VIP customer rules
  2. High Priority (7-8): Time-sensitive or critical tickets
  3. Medium Priority (4-6): Specific routing by type or category
  4. Low Priority (1-3): General catch-all rules
  5. Base Priority (0): Default fallback rule

Base Support Rotation

The system automatically creates a base assignment rule:
  • Named “Base Support Rotation”
  • Priority: 0
  • Serves as catch-all for unmatched tickets
  • Referenced in HD Settings (hd_settings.json:90-95)
You must always have at least one assignment rule for HD Ticket. The system prevents deletion of the last rule (see helpdesk/extends/assignment_rule.py:7-12).

Manual Assignment Override

Agents can manually assign or reassign tickets:

Manual Assignment

1

Open Ticket

Navigate to the ticket you want to assign.
2

Click Assign

Use the assignment button or modal.
3

Select Agent

Search for and select the agent. Only agents (users with HD Agent role) can be assigned.
4

Confirm Assignment

The ticket is assigned and the agent receives a notification.
Manual assignments override automatic rules and are not changed by subsequent rule evaluations unless unassign conditions are met.

Self-Assignment

Agents can assign tickets to themselves:
# Implementation in helpdesk/api/ticket.py:5-19
def assign_ticket_to_agent(ticket_id, agent_id=None):
    if not agent_id:
        # assign to self
        agent_id = frappe.session.user
    
    # Validation: only agents can be assigned
    if not frappe.db.exists("HD Agent", agent_id):
        frappe.throw(_("Tickets can only be assigned to agents"))

Workload Distribution

Preventing Overload

Use load balancing to distribute work fairly:
  1. Count Open Tickets: System counts tickets per agent
  2. Assign to Least Loaded: New ticket goes to agent with fewest open tickets
  3. Rebalance on Status Change: Counts update when tickets are resolved

Capacity Limits

While not built-in, you can implement capacity limits:
# Custom condition to check agent capacity
agent_ticket_count = frappe.db.count('HD Ticket', {
    '_assign': ['like', f'%{agent.name}%'],
    'status_category': 'Open'
})
agent_ticket_count < 20  # Max 20 open tickets per agent

Unassignment Automation

Automatically remove assignments when conditions are met:

Unassign on Resolution

[["status_category", "==", "Resolved"]]

Unassign on Transfer

[["agent_group", "!=", "Support Team"]]

Unassign on Escalation

doc.priority == 'Urgent' and doc.status == 'Escalated'

Notifications

When tickets are assigned:
  1. Agent Notification: Assigned agent receives an in-app notification
  2. Notification Type: “Assignment” notification (see hd_ticket.py:232-241)
  3. Email Notification: Optional email alert based on agent preferences

Testing Assignment Rules

1

Create Test Tickets

Create tickets that match your rule conditions:
  • Set ticket_type, priority, etc. to match conditions
  • Use different combinations to test all rules
2

Verify Assignments

Check that tickets are assigned to the expected agents:
  • Review assignment history
  • Verify correct rule was applied
  • Check assignment strategy (round-robin, load balancing)
3

Test Edge Cases

Try scenarios like:
  • No matching rules (should use base rotation)
  • Multiple matching rules (should use highest priority)
  • All agents at capacity
  • Unassign conditions
4

Monitor Performance

After deploying rules:
  • Track assignment distribution
  • Measure response times
  • Identify bottlenecks
  • Adjust rules as needed

Common Assignment Patterns

By Ticket Type

// Billing tickets to billing team
[["ticket_type", "==", "Billing"]]

// Technical tickets to technical team
[["ticket_type", "==", "Technical Issue"]]

By Customer Tier

# Enterprise customers to senior agents
customer_tier = frappe.db.get_value('Customer', doc.customer, 'tier')
customer_tier == 'Enterprise'

By Priority

// Urgent tickets to senior team
[["priority", "in", ["Urgent", "High"]]]

By Channel

# Phone tickets to phone support team
doc.content_type == 'Phone'

# Email tickets to email team
not doc.via_customer_portal

By First-Time Customer

// New customers to onboarding team
[["is_first_ticket", "==", 1]]

By Agent Group

// Route within assigned team
[["agent_group", "==", "Support Team"]]

Best Practices

Rule Design

  1. Start Simple: Begin with basic rules and add complexity as needed
  2. Use Clear Names: Descriptive names help with troubleshooting
  3. Document Conditions: Add descriptions explaining rule logic
  4. Test Thoroughly: Verify rules work as expected before going live
  5. Monitor Performance: Track metrics to ensure rules are effective

Condition Writing

  1. Use Portal Builder: Visual builder prevents syntax errors
  2. Keep Conditions Simple: Complex logic is harder to maintain
  3. Avoid Hardcoding: Use dynamic lookups instead of static values
  4. Handle Null Values: Check for existence before comparing
  5. Test Edge Cases: Verify behavior with missing or unusual data

Team Management

  1. Balance Workload: Use load balancing for fair distribution
  2. Match Expertise: Route tickets to qualified agents
  3. Cross-Train Teams: Avoid single points of failure
  4. Set Capacity Limits: Prevent agent overload
  5. Review Regularly: Adjust rules as team composition changes

Maintenance

  1. Audit Rules Quarterly: Review and update outdated rules
  2. Remove Unused Rules: Delete or disable rules no longer needed
  3. Update Assignee Lists: Keep agent lists current
  4. Monitor Assignment Metrics: Track which rules are most active
  5. Gather Team Feedback: Ask agents if routing is effective

Troubleshooting

Tickets Not Assigned

Issue: New tickets aren’t being assigned automatically Solutions:
  1. Check that assignment rules are enabled
  2. Verify conditions match ticket properties
  3. Ensure assignee list includes active agents
  4. Review rule priority order
  5. Check for validation errors in conditions

Wrong Agent Assigned

Issue: Tickets go to incorrect agents Solutions:
  1. Review rule conditions for accuracy
  2. Check priority order of rules
  3. Verify ticket field values match expected
  4. Test conditions with sample data
  5. Review agent group membership

Uneven Distribution

Issue: Some agents get too many tickets Solutions:
  1. Use load balancing instead of round-robin
  2. Check if agent is in multiple assignment rules
  3. Review manual assignment overrides
  4. Verify all agents are active
  5. Consider implementing capacity limits

Rules Not Evaluating

Issue: Assignment rules don’t seem to run Solutions:
  1. Check that document type is “HD Ticket”
  2. Verify rule is not disabled
  3. Check for syntax errors in conditions
  4. Review system logs for errors
  5. Ensure base support rotation exists

Build docs developers (and LLMs) love