Workflow recipe: Assign a ticket to the last agent that served the requester


What's my plan?




Suite
Team, Growth, Professional, Enterprise, or Enterprise Plus








Support
Team, Professional, or Enterprise





Some organizations assign new tickets to the agent who last assisted a requester to ensure continuity and personalization.
In this recipe, you'll learn how to replicate this workflow with custom user fields and business rules.
This article contains the following topics:

Workflow goal
Creating a custom user field
Creating a webhook to update the ticket requester
Creating a trigger to save the last assigned agent
Creating a webhook to update tickets
Creating a trigger to assign tickets based on the last handling agent
Notes and tips

Workflow goal
In this workflow, you'll set up custom user fields, webhooks, and triggers so that the last agent who assisted a requester is assigned subsequent tickets from that same requester.
When you're done setting up this workflow, the first time a requester submits a ticket, any agent can be assigned to it manually or based on another rule. After the requester submits their first ticket, any new ticket from that requester will automatically be assigned to the last agent who handled their previous ticket.
Creating a custom user field
The first thing you need to do is store who the last agent was that worked on a ticket. To do this, you'll start by creating a custom user field to store that information for each end user.
To create a custom user field:

In the Admin Center, click People in the sidebar, then select Configuration > User Fields.
Click Add Field.
Select Text as the field type.
In the Display Name field enter Handler agent. This automatically sets the Field key to handler_agent.
(Optional) Enter a Description for the custom field.

Click Save.

See Adding custom fields to users for more information.
Creating a webhook to update the ticket requester
Next, you'll update the custom user field you created by setting up a webhook that updates a user.
To create the webhook:

In the Admin Center, click Apps and Integrations in the sidebar, then select Webhooks > Webhooks.
Click Create Webhook.
Use the following values for your configuration:


Name: Update user handler agent

Endpoint URL: https://yourdomain.zendesk.com/api/v2/users/{{ticket.requester.id}}.json


Request method: PUT

Request format: JSON

Authentication: Basic authentication See Creating webhooks to interact with third-party systems for more information.



Creating a trigger to save the last assigned agent
Next, you'll create a trigger to invoke the webhook you created to update the custom user field with the agent ID.
This trigger uses the webhook to update the custom user field linked to the ticket requester with the agent ID each time a ticket assignee changes.
To create a ticket trigger to use the webhook:

In Admin Center, click Objects and rules in the sidebar, then select Business rules > Triggers.
Click Create trigger.
Enter a Trigger name, such as Assign handler agent.
(Optional) Enter a Description and a Category.
In the Conditions section, under Meet ALL of the following conditions, add the following conditions:

Ticket: Assignee | Changed
Ticket: Assignee | Is not | (blank)

Ticket: Ticket | is | Updated




In the Actions section, add the following:

Notify by: Active Webhook | Update user handler agent
Use the following for the JSON Body:



{
"user": {
"user_fields": {
"handler_agent": "{{ticket.assignee.id}}"
}
}
}

Click Create. See Creating ticket triggers for automatic ticket updates and notifications for more information.

Creating a webhook to update tickets
Next, you'll create a second webhook to update the relevant ticket via REST API.
To create the webhook:

In the Admin Center, click Apps and Integrations in the sidebar, then select Webhooks > Webhooks.
Click Create Webhook.
Use the following values for your configuration:





Name: Update ticket

Endpoint URL: https://yourdomain.zendesk.com/api/v2/tickets/{{ticket.id}}.json


Request method: PUT

Request format: JSON

Authentication: Basic Authentication See Creating webhooks to interact with third-party systems for more information.



Creating a trigger to assign tickets based on the last handling agent.
Finally, you'll create a trigger to check if a ticket has a previously assigned agent. This information is used to assign new tickets.
To create the trigger:



In Admin Center, click Objects and rules in the sidebar, then select Business rules > Triggers.
Click Add trigger.
Enter a Trigger name, such as Assign ticket to end user handler agent.
(Optional) Enter a Description and a Category for your trigger.
In the Conditions section, under Meet ALL of the following conditions, add the following conditions:


Ticket: Ticket | Is | Created


Requester: Handler_agent | Is not | (blank)




In the Actions section, add the following actions:

Notify by: Active Webhook | Update ticket
Use the following for the JSON Body:





{
"ticket": {
"assignee_id": "{{ticket.requester.custom_fields.handler_agent}}"
}
}
The trigger action should be similar to the image below:

Notes and tips

Make sure agents don't delete or modify the handler_agent custom user field unless necessary.
You can combine this setup with business hours, priority rules, or SLAs.
Introduce new conditions to the trigger to meet your business’ use case.
Test the flow thoroughly in a sandbox or test account before deploying it live.



//
const banner_style = document.createElement('style');
banner_style.innerHTML = `#article-body #docs-wmp-link{text-align:right;font-size:.8em}#article-body .article-banners{margin-bottom:1rem}#article-body .article-banner{border:1px solid #ded7ca;background-color:#f6f0e6;margin:0 0 3px;line-height:1}#article-body .article-banner table{border-collapse:collapse;border:none;margin:0;width:auto}#article-body .article-banner td{padding:8px 6px 8px;border:none;font-size:.85em}#article-body .article-banner td:nth-child(2){border-left:1px solid #d0c9bd}#article-body .article-banner strong{font-weight:400;text-shadow:0 0 1px rgba(0,0,0,.5);letter-spacing:.5px}@media (min-width:1600px){#article-body .article-banner td{font-size:.8em}#article-body .docs-wmp-link{font-size:.7em}}`;
document.head.appendChild(banner_style);
//

