Welcome to Portal

?Unknown\pull-down

Welcome to Zoho Cares

Bienvenido a Soporte de Zoho

Search our knowledge base, ask the community or submit a request.



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.

4 users like this announcement.
35 Replies
Reply
15 more

og and then he sometimes says:
Argument type mismatch - Found 'TEXT' but Expected '[KEY-VALUE, TEXT, LIST]' for the function 'get

  • 3 years ago

The function is up-to-date, and it should work when executed, Timo. We might have to pull you into a ticket to investigate the error and ascertain the cause. Drop us a line at support@zohodesk.com with the screenshot of the error message for further scrutiny.


Regards,
Ash | Zoho Desk

Hello

Since custom functions are not available in the professional version, is it true that attachments will not flow to tickets?

  • 3 years ago

They will, Jeffrey. Just that the attachments on the threads wouldn't be uploaded to the Attachments tab automatically.


Regards,
Ash | Zoho Desk

So glad this post exists!

I'm hoping to put this code into action, but am running into a few issues. (Warning, this is my first time using Deluge.)

1) Which spots do we need to replace the AuthToken? I saw Ash's video about using connections (https://www.youtube.com/watch?v=j1WF-90oDuU).
2) Where on the page can we do this step: Argument Mapping > Name: ticketID & Value: Ticket Id ?


My ultimate goal is to have all attachments (both received from contacts or sent to contacts) automatically populate in the attachments tab of the tickets. If there is a newer way of doing this, please let me know!

Thank you,
Annah

  • 2 years ago

I'd suggest reaching out to us at support@zohodesk.com so that we can help implement the custom function via screen-sharing session, Annah.


Regards,
Ash | Zoho Desk

I'm getting the following error trying to create this Function.  Any ideas?

Failed to update function
Error due to - 'Connection zohosupport does not exist' Line Number : 6

  • 2 years ago

Given the nature of this request, I'd suggest dropping us a note at 'support@zohodesk.com' for further assistance, Jesse.


Regards,
Ash | Zoho Desk

  • Zoho MVP
  • 1 year ago

A quick tip for all those who encounter problems. I have noticed that it is problematic when there are many attachments (about 8 or more). Then this function no longer uploads all attachments correctly to the ticket attachment. I have received the following feedback from support and think that it may be useful or could become useful for others.



We have identified the cause of the failure. The issue stems from a custom function being invoked before writing file content to the file system. Introducing a delay in the custom function code should resolve the problem. Please incorporate the following snippet at the beginning of the function code:

 

delayResponseCall = invokeurl

[

  url: "
https://postman-echo.com/delay/8"


  type: GET

];

 

 

It's important to note that this is a temporary workaround


  • 1 year ago

Thank you for sharing it, Sven.


Regards,
Ash | Zoho Desk

Please can we have an up to date way of doing this??

  • 11 months ago

Could you care to elaborate on the problem you are facing with the above code, Jake? It should chalk up the requirement till date.


Regards,
Ash | Zoho Desk

Thanks for the code & tips!

However, as others flagged, it is not reliable. Once you have multiple files attached or one bigger file with 3 or more smaller, it will not work depending on if the trigger is ticket creation/reply or Agent reply and comment.

Addiing a delay did helped a bit, but for ticket creation and customer replies, even adding a "50" delay is not working.

delayResponseCall = invokeurl
[
  url: "
https://postman-echo.com/delay/50"
  type: GET
];

Hope we can have the option soon!

  • 9 months ago

Noted, François. Thank you for adding your inputs here. 


Regards,
Ash | Zoho Desk

  • 7 months ago

As stated, this should help you fetch attachments from incoming or outgoing response of a ticket and update them under tickets attachments tab.

It works with email attachment but not for attachments attached in comments (new tongue twister).

How can I modify the custom function to allow it ?

Hi Mauricio,
We need to adjust the custom function to fetch comment attachments. Please contact us at support@zohodesk.com for the modified custom function script.

Regards,
Ajith | Zoho Desk

  • 6 months ago

Hello, is there any alternative solution for the Pro edition since the execute function action is not available in the Pro edition of Desk?

Hi @Thao Pham,

Unfortunately, this isn’t something that’s supported through native features. Sorry about that!

Regards,  
Shivani | Zoho Desk

Great function, thank you.
Can it also add attachments that have been attached to a comment? 

Hi @Kate Woollard,
 
Happy to hear you liked this feature :) Absolutely, it’s possible to fetch the comment’s attachment and add it as a ticket attachment. We’ll tweak the script and share it with you via #108678008.
 
Cheers,
Shivani | Zoho Desk

Reply to Chinmayee MishraA
/* */
  • 12
  • Insert
  • Plain text
Add Comment
(Up to 20 MB )