Auto assignment of tickets to an agent in Zoho Desk based on Account owner in Zoho CRM

Auto assignment of tickets to an agent in Zoho Desk based on Account owner in Zoho CRM

Hello everyone!

I have written a custom function in Zoho Desk to automatically assign a ticket to an agent in Zoho Desk based on the account owner in Zoho CRM when a new ticket is created in Zoho Desk. I hope this helps who need it.

You must create a workflow to automate this. To create a workflow, follow below steps.

Step 1: Basic Information
  1. Click the Setup icon in the top bar.
  2. In the Setup Landing page, click Workflows under Automation.
  3. In the Workflows List page, click Create Rule in the upper-right area.
  1. In the New Workflow page, do the following:
  2. Select the Ticket module.
  3. Enter the Rule Name.
  4. Select the Active checkbox.
  5. Enter the Description for the workflow rule.
  6. Click Next.
Step 2: Execute On
  1. In the Execute On section, select Create.
  2. Click Next.

Part 3: Actions
  1. Under Actions, click the Add Custom Function icon and select an New custom function.
  1. Enter function Name.
  2. Click on Edit Arguments and enter argument name ticketId and select value Ticket Id.
  3. Click Done.

Pre-requisites:

1. Create connection in Zoho Desk with following scopes for Zoho CRM service
      ZohoCRM.modules.contacts.READ, ZohoSearch.securesearch.READ
2. Create connection in Zoho Desk with following scopes for Zoho Desk service
      Desk.settings.READ, Desk.basic.READ

Paste below code in editor. Replace orgId with your org ID.
  1. orgId = 123456789; // organization ID. Replace it with your Org Id.
  2. ticketRecord = zoho.desk.getRecordById(orgId,"tickets",ticketId); //  ticketId to be mapped as an argument
  3. contactEmail = ticketRecord.get("email"); //extracts the contact person's email ID from the ticket record
  4. departmentId = ticketRecord.get("departmentId"); //extracts department id from the ticket record
  5. // search for a matching contact in Zoho CRM
  6. contactSearchResponse = invokeurl
  7. [
  8. url : "https://www.zohoapis.com/crm/v6/Contacts/search?email=" + contactEmail
  9. type : GET
  10. connection: "zcrm"
  11. ];
  12. // checks if a matching contact is found in Zoho CRM by checking the size of the response data
  13. if(contactSearchResponse.get("data").size() > 0)
  14. {
  15. data = contactSearchResponse.get("data").get(0);
  16. contactOwnerEmail = data.get("Owner").get("email"); // extracts the contact owner's email ID
  17. accountRecord = zoho.crm.getRecordById("Accounts", data.get("Account_Name").get("id"));
  18. contactOwnerId = data.get("Owner").get("id");
  19. accountOwnerId = accountRecord.get("Owner").get("id");
  20. //contact owner's ID and account owner's ID are compared to check if they are the same
  21. //If the contact owner and account owner are the same, search for a matching agent in Zoho Desk
  22. if ( contactOwnerId == accountOwnerId )
  23. {
  24. headerMap = Map();
  25. headerMap.put("orgId",orgId);
  26. agentSearchResponse = invokeurl
  27. [
  28. url : "https://desk.zoho.com/api/v1/agents/email/" + contactOwnerEmail
  29. type : GET
  30. headers: headerMap
  31. connection: "zdesk"
  32. ];
  33. agentId = agentSearchResponse.get("id");
  34. departmentList = agentSearchResponse.get("associatedDepartmentIds");
  35. // check if the matching agent has access to the department associated with the ticket
  36. // If the agent has access to the department, assign the ticket to the agent
  37. if(departmentList.contains(departmentId) == true)
  38. {
  39. agentMap = Map();
  40. agentMap.put("assigneeId",agentId);
  41. agent = agentMap.toString();
  42. ticketResponse = invokeurl
  43. [
  44. url : "https://desk.zoho.com/api/v1/tickets/" + ticketId
  45. type : PUT
  46. parameters: agent
  47. headers: headerMap
  48. connection: "zdesk"
  49. ];
  50. }
  51. }
  52. }
Best Regards,
Subhash Kumar

    Access your files securely from anywhere

        Zoho Developer Community




                                  Zoho Desk Resources

                                  • Desk Community Learning Series


                                  • Digest


                                  • Functions


                                  • Meetups


                                  • Kbase


                                  • Resources


                                  • Glossary


                                  • Desk Marketplace


                                  • MVP Corner


                                  • Word of the Day



                                      Zoho Marketing Automation
                                              • Sticky Posts

                                              • Webinar 2: Supercharged customer support for growing business

                                                Join us for this webinar and learn how to step up your support game using a real-time communication platform to generate happier, more successful customers. In this live webinar, we will will discuss the importance of SalesIQ for your support team and how it can help you:  Understand your customers better and their journeys to proactively support and engage them even before they ask for help.  Integrating real time conversations into Zoho Desk’s Support, providing a conversational customer service
                                              • Customize Colors of your Customer Self Service Portal

                                                You asked for it. We heard you. We're happy to roll out the most sought after feature request, Customizing the Colors of your Customer Self-service Portal. Now you can set the color of your customer portal to mimic your company's web site, so that your customers visiting the portal will not feel alienated by the default theme.  Go ahead and configure the color of the header, tabs, fonts and background according to your needs. You can either choose between default color themes like Blue, Grey, Green
                                              • Edit and Delete options in Comments

                                                A lot of teams have been using ticket comments extensively to collaborate everyday. Notification Center further improved this experience by bringing real-time updates. As we continue to build more improvements to this experience, we've shipped a small-yet-important
                                              • 2024 Email Authentication Standards: Elevating Security with Google and Yahoo

                                                In contemporary email communication, email authentication plays a pivotal role in mitigating email fraud, spam, and phishing attacks. Brace yourself for a new level of security. Starting February 2024, Gmail and Yahoo will be implementing robust email
                                              • Announcing the New and Improved Article Editor

                                                KBase articles are known to help customers, find solutions to problems on their own and set the stage for ticket deflection. That said, the way you present your KBase content is the clinching factor that ensures your customers stick around to consume it.  We took it upon ourselves to build an editor that allows you to publish articles without delving into the code. Well, at least for the most part. With more options and a redefined interface, the article editor in Zoho Desk is now better than ever!


                                              Manage your brands on social media



                                                    Zoho TeamInbox Resources

                                                      Zoho DataPrep Resources



                                                        Zoho CRM Plus Resources

                                                          Zoho Books Resources


                                                            Zoho Subscriptions Resources

                                                              Zoho Projects Resources


                                                                Zoho Sprints Resources


                                                                  Qntrl Resources


                                                                    Zoho Creator Resources



                                                                        Zoho Campaigns Resources


                                                                          Zoho CRM Resources

                                                                          • CRM Community Learning Series

                                                                            CRM Community Learning Series


                                                                          • Kaizen

                                                                            Kaizen

                                                                          • Functions

                                                                            Functions

                                                                          • Meetups

                                                                            Meetups

                                                                          • Kbase

                                                                            Kbase

                                                                          • Resources

                                                                            Resources

                                                                          • Digest

                                                                            Digest

                                                                          • CRM Marketplace

                                                                            CRM Marketplace

                                                                          • MVP Corner

                                                                            MVP Corner





                                                                              Design. Discuss. Deliver.

                                                                              Create visually engaging stories with Zoho Show.

                                                                              Get Started Now