Ticket Routing with Server Scripts
Server Scripts allow you to automate ticket routing by executing Python code whenever a ticket is created or updated. This enables Helpdesk to assign tickets to the appropriate team based on predefined business rules without requiring a custom app.
Server Scripts are ideal for implementing custom routing logic based on ticket fields, email accounts, customer information, or any other data available on the ticket.
Tip
Server Scripts execute on the server, allowing you to automate workflows without modifying Helpdesk’s source code or deploying a custom application.
Before You Begin
Server Scripts must be enabled in your Frappe site.
Create a new Server Script from Desk and configure it to run on the HD Ticket DocType using the appropriate event (such as Before Insert or Before Save) depending on your workflow.
Route Tickets by Ticket Type
You can automatically assign tickets to different teams based on the selected ticket type.
The agent_group field represents the Team assigned to the ticket.
if (doc.ticket_type == "Bug"):
doc.agent_group = "Frappe Cloud"
elif (doc.ticket_type == "Customization"):
doc.agent_group = "Billing"
else:
doc.agent_group = "Product Experts"
In this example:
- Bug reports are assigned to the Frappe Cloud team.
- Customization requests are assigned to the Billing team.
- All other tickets are assigned to the Product Experts team.
Route Tickets by Email Account
If your organization receives support requests through multiple email addresses, you can route tickets based on the email account that received the message.
if (doc.email_account == "Accounting"):
doc.agent_group = "L1 Accounting"
elif (doc.email_account == "Warehouse"):
doc.agent_group = "L2 Warehouse"
else:
doc.agent_group = "L1"
This approach is useful when different departments manage separate support mailboxes.
Route Tickets by Custom Fields
You can also build routing rules using custom fields added to the HD Ticket DocType.
For example, if you’ve added a custom field named custom_category, you can assign tickets based on its selected value.
if (doc.custom_category == "Frappe Cloud"):
doc.agent_group = "Frappe Cloud"
elif (doc.custom_category == "Accounting"):
doc.agent_group = "Billing"
else:
doc.agent_group = "Product Experts"
This is particularly useful for automatically routing tickets created through customized ticket forms or customer portals.
Supported Routing Criteria
Since Server Scripts have access to the ticket document, you can build routing rules using virtually any field, including:
- Ticket Type
- Email Account
- Priority
- Customer
- Organization
- Custom Fields
- Subject or Description
- Any other field available on the HD Ticket DocType
Example Use Cases
- Route bug reports to the Engineering team.
- Assign billing-related tickets to the Finance team.
- Distribute tickets based on the customer’s region.
- Route tickets received through different support email addresses.
- Assign tickets based on custom categories selected in the Customer Portal.
Best Practices
- Keep routing logic simple and easy to maintain.
- Use descriptive team names that match your Helpdesk configuration.
- Test Server Scripts in a staging environment before deploying them to production.
- Use custom fields when standard ticket fields aren’t sufficient for routing decisions.
- Document your routing rules so administrators can easily update them as your support workflow evolves.
Note
The value assigned to doc.agent_group must exactly match the name of an existing Helpdesk Team. If the specified team does not exist, the ticket will not be assigned correctly.