Automation #3 - Auto-sync email attachments to tickets

Automation #3 - Auto-sync email attachments to tickets



This is a monthly series where we pick some common use cases that have been either discussed or most asked about in our community and explain how they can be achieved using one of the automation capabilities in Zoho Desk.

Most of our customers use email as their primary channel for customer support. Keeping that in mind we ensured Zoho Desk's multi-channel capability allowed for every email received in your inbox to be automatically converted into tickets in Zoho Desk. But for some time now, we have been receiving question on how to convert email attachments into ticket attachments within Zoho Desk. This process, which is mostly achieved manually now by many customers, can be automated using a simple script.

This automation involves two components: a connection and a workflow rule. We will first start by creating the connection and then set up the workflow rules to execute the custom function.

To create the connection, perform the following steps:
  1. Go to Setup > Connections under Developer Space
  2. Click "Create Connection"
  3. Select "Zoho OAuth" under "Default Connection"
  4. Give the connection name as "ticketattachment"
  5. Under Scope below values
    Desk.tickets.READ
    Desk.tickets.UPDATE
  6. Click "Create and Connect"
  7. Click "Connect" and click "Accept"
Connection is created successfully.

To create workflow rule and associate custom function, perform the following steps:
  1. Go to Setup, and under Automation, click Workflows.
  2. On the left panel, under Workflows, click Rules > Create Rule,
    In the Basic Information section, carry out the following steps:
  3. In the Module drop-down menu, select Tickets.
  4. Enter a name and description for the rule.
  5. If you want to activate the rule right away, select the Active checkbox. Else, you can just create the rule now and activate it later, on the Rules page.
  6. Click Next.
    In the Execute on section, perform the following steps:
  7. Select the Create checkbox to execute this rule every time a new ticket is created. 
    NOTE: If you would like to fetch all the attachment sent out and received in tickets, select "Customer Reply" and "Agent Response"
  8. Click Next, skip the "Criteria" and Click Next.
  9. In the Actions section, carry out the following steps:
  10. Click the + icon under "Action" and select "New" next to Custom Functions
  11. Enter a name and description for the custom function.
  12. In the script window, input the Custom Function you find below:

    1. //Replace your zoho desk URL accordingly
    2. getTicketThread = invokeurl
    3. [
    4. url :deskDomain + "/api/v1/tickets/" + ticketID + "/latestThread"
    5. type :GET
    6. connection:"ticketattachment"
    7. ];
    8. dir = getTicketThread.get("direction");
    9. info "Direction " + dir;
    10. if(dir == "in")
    11. {
    12. prefix = "customer_";
    13. }
    14. else
    15. {
    16. prefix = "agent_";
    17. }
    18. listAttachments = getTicketThread.get("attachments");
    19. for each  attach in listAttachments
    20. {
    21. attachmentURL = attach.get("href");
    22. filename = prefix + attach.get("name");
    23. getAttachment = invokeurl
    24. [
    25. url :attachmentURL
    26. type :GET
    27. connection:"ticketattachment"
    28. ];
    29. if(getAttachment != null)
    30. {
    31. if(isText(getAttachment))
    32. {
    33. getAttachment = getAttachment.toFile(filename);
    34. }
    35. //info getAttachment;
    36. param = Map();
    37. param.put(filename,getAttachment);
    38. getAttachment.setParamName("file");
    39. uploadResponse = invokeurl
    40. [
    41. url :deskDomain + "/api/v1/tickets/" + ticketID + "/attachments"
    42. type :POST
    43. parameters:param
    44. headers: {"Content-Type":"multipart/form-data"}
    45. connection:"ticketattachment"
    46. ];
    47. info uploadResponse;
    48. }
    49. }
  13. Click Edit Arguments
  14. In the Name field type TicketID, and from the Value drop-down list select Ticket Id under Ticket Information
  15. Click "Save" to save the custom function
  16. Click "Save" again to save the workflow.
This should help you fetch attachments from incoming or outgoing response of a ticket and update them under tickets attachments tab.

      • Sticky Posts

      • Zoho Desk Virtual Meetup: US Central, October 5 - 7, 2021

        After the interactive Virtual Meetups in the other regions, we are starting with the US Central and Midwest regions from October 5 to October 7, 2021. The dates for other regions will be announced soon.  At this event, we will explore the topics which
      • Register for Zoho Desk Beta Community

        With the start of the year, we have decided to take a small step in making the life of our customers a little easier. We now have easy access to all our upcoming features and a faster way to request for beta access. We open betas for some of our features
      • Ask the Experts 10: A 5-hour online Q&A on Zoho Desk Best Practices

        Welcome to Zoho Desk's Ask the Experts session! This is a monthly discussion on our  forums; wherein a panel of experts will take on questions  specific to topics related to Zoho Desk. The panel will be available for a 5-hour period and will answer any questions posted here.   Let's begin the year learning some best practices from our experts. In this month's ATE we are opening the floor to questions on how to use Zoho Desk the best way.  If you have a business use case but not sure if Workflow is
      • Share your Zoho Desk story with us!

        Tell us how you use Zoho Desk for your business and inspire others with your story. Be it a simple workflow rule that helps you navigate complex processes or a macro that saves your team a lot of time; share it here and help the community learn and grow with shared knowledge. 
      • Ask the Experts 7: A 5-hour online Q&A on Telephony and Call Module

        Welcome to Ask the Experts session! This is a monthly discussion in forums; each session, a panel of experts will take questions on specific topics related to Zoho Desk. The panel will be available for a 5-hour period and answer any questions posted here. In this month's Ask the Experts, we will take questions on everything related to Telephony and the Call Module in Zoho Desk. We will discuss the following aspects:  Integration with different Telephony vendors Routing calls to agents Converting