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:

  1. In the Admin Center, click    People in the sidebar, then select Configuration > User Fields.
  2. Click Add Field.
  3. Select Text as the field type.
  4. In the Display Name field enter Handler agent.
    This automatically sets the Field key to handler_agent.
  5. (Optional) Enter a Description for the custom field.
  6. 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:

  1. In the Admin Center, click  Apps and Integrations in the sidebar, then select Webhooks > Webhooks.
  2. Click Create Webhook.
  3. 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:

  1. In Admin Center, click Objects and rules in the sidebar, then select Business rules > Triggers.
  2. Click Create trigger.
  3. Enter a Trigger name, such as Assign handler agent.
  4. (Optional) Enter a Description and a Category.
  5. 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

  6. 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}}" 
        } 
    } 
}
  1. 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:

  1. In the Admin Center, click  Apps and Integrations in the sidebar, then select Webhooks > Webhooks.
  2. Click Create Webhook.
  3. 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:

    1. In Admin Center, click Objects and rules in the sidebar, then select Business rules > Triggers.
    2. Click Add trigger.
    3. Enter a Trigger name, such as Assign ticket to end user handler agent.
    4. (Optional) Enter a Description and a Category for your trigger.
    5. 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)

    6. 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.

Powered by Zendesk