-
Go to Setup, and under Automation, click Workflows.
-
On the left panel, under Workflows, click Rules > Create Rule,
In the Basic Information section, carry out the following steps:
-
In the Module drop-down menu, select Tickets.
-
Enter a name and description for the rule.
-
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.
-
Click Next.
In the Execute on section, perform the following steps:
-
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"
-
Click Next, skip the "Criteria" and Click Next.
-
In the Actions section, carry out the following steps:
-
Click the + icon under "Action" and select "New" next to Custom Functions
-
Enter a name and description for the custom function.
In the script window, input the Custom Function you find below:
-
-
//Replace your zoho desk URL accordingly
-
getTicketThread = invokeurl
-
[
-
url :deskDomain + "/api/v1/tickets/" + ticketID + "/latestThread"
-
type :GET
-
connection:"ticketattachment"
-
];
-
dir = getTicketThread.get("direction");
-
info "Direction " + dir;
-
if(dir == "in")
-
{
-
prefix = "customer_";
-
}
-
else
-
{
-
prefix = "agent_";
-
}
-
listAttachments = getTicketThread.get("attachments");
-
for each attach in listAttachments
-
{
-
attachmentURL = attach.get("href");
-
filename = prefix + attach.get("name");
-
getAttachment = invokeurl
-
[
-
url :attachmentURL
-
type :GET
-
connection:"ticketattachment"
-
];
-
if(getAttachment != null)
-
{
-
if(isText(getAttachment))
-
{
-
getAttachment = getAttachment.toFile(filename);
-
}
-
//info getAttachment;
-
param = Map();
-
param.put(filename,getAttachment);
-
getAttachment.setParamName("file");
-
uploadResponse = invokeurl
-
[
-
url :deskDomain + "/api/v1/tickets/" + ticketID + "/attachments"
-
type :POST
-
parameters:param
-
headers: {"Content-Type":"multipart/form-data"}
-
connection:"ticketattachment"
-
];
-
info uploadResponse;
-
}
-
}
-
Click Edit Arguments
-
In the Name field type TicketID, and from the Value drop-down list select Ticket Id under Ticket Information.
Click "Save" to save the custom function
-
Click "Save" again to save the workflow.