HOW TO: Searching a thread (email body/text) with a custom function, allowing filtering and specific actions

HOW TO: Searching a thread (email body/text) with a custom function, allowing filtering and specific actions

We are still trialing out Zoho at this time, but have found a major expected feature to be missing - the ability to search within the text of an email for automation/workflows.

NOTE: You need to create a connection for zohodesk under settings -> Developer Space -> Connections. We named our connection zohodesk with link name 'zohodesk' and under choose scopes select all options.

I am sharing my current solution that may benefit other users needing similar functionality.
  1. For my example I created a Workflow for the Tickets Module.
  2. You can have this execute by any method, I have this execute on create (customer emails).
  3. For Criteria you may add what is necessary, but I have the criteria filtering (by searching email text) within the custom function and have section 3 "Criteria" empty.
  4. For Actions hit '+' and choose 'Custom Functions' (new or existing if you already made this)
Name your custom function something internally identifiable.

The Custom Function:
OrgID = ####;
getthreads = zoho.desk.getRelatedRecords(OrgID,"threads","tickets",ticketId,0,1);
threadid = getthreads.getJSON("data").getJSON("id");
getthreadcontent = zoho.desk.getRelatedRecordById(OrgID,"threads",threadid,"tickets",ticketId).getJSON("content");
if(getthreadcontent.containsIgnoreCase("cancel"))
{
updateticket = zoho.desk.update(OrgID,"tickets",ticketId,{"status":"Cancel"});
info updateticket;
}

Custom Function Notes:
  1. Update OrgID to your organization ID in zohodesk
  2. Replace 'cancel' under if(getthreadcontent.containsIgnoreCase("cancel")) to any keyword/phrase you want to search
  3. Change .containsIgnoreCase to .contains for case sensitive searches
  4. Under updateticket we are updating 'ticket' and the field is 'status' changing it to our custom text of Cancel. Here you can use different modules or fields to update - see full details here: https://www.zoho.com/deluge/help/desk/update-record.html
You can see all values you can update for the 'ticket' module here: https://desk.zoho.com/DeskAPIDocument#Tickets#Tickets_Updateaticket under 'Attributes'

This is the nearest solution that we expanded on: https://help.zoho.com/portal/en/community/topic/automation-6-prevent-re-opening-of-closed-tickets-16-9-2020
  1. This solution copies the thread (email body) to the description field
  2. The description field does have a limitation on length from my research
  3. Doing this duplicated every thread and showed two conversations
  4. The solution I posted above does not duplicate threads/conversations and allows searchability within the function instead of copying to description and then searching description
  5. Copying description and having another workflow 'search' description does not work as the workflows execute at the same time and the clone to description doesn't complete until after workflows execute.