Create a task in Zoho CRM directly from Zoho Cliq

Create a task in Zoho CRM directly from Zoho Cliq

Components used : Slash command, message action.

Slash Command:

To create a task in Zoho CRM directly from a chat window in Zoho Cliq, follow the steps below:

Step 1: Create a command

The first step is to create a command in Zoho Cliq that allows users to create a task directly from a chat window. To do this, go to your profile, then navigate to  Bots & Tools > Integrations > Command > Create Command .

In the command creation window, you will need to enter a name for your command, a description, and choose the access level (Personal, Team, or Org). Once you have done this, save the command.

Next, paste the provided code in the script editor in the integration window:

  1. fetchFields = invokeurl
  2. [
  3.  url :"https://www.zohoapis.com/crm/v2/settings/fields?module=Tasks"
  4.  type :GET
  5.  connection:"CONNECTION LINK NAME"
  6. ];
  7. //info fetchFields;
  8. allFields = fetchFields.get("fields");
  9. priorityList = list();
  10. statusList = list();
  11. for each  field in allFields
  12. {
  13.  if(field.get("api_name") == "Priority")
  14.  {
  15.   pickListValues = field.get("pick_list_values");
  16.   for each  pickList in pickListValues
  17.   {
  18.    displayName = pickList.get("display_value");
  19.    priorityList.add({"label":displayName,"value":displayName.replaceAll(" ","_")});
  20.   }
  21.  }
  22.  else if(field.get("api_name") == "Status")
  23.  {
  24.   pickListValues = field.get("pick_list_values");
  25.   for each  pickList in pickListValues
  26.   {
  27.    displayName = pickList.get("display_value");
  28.    statusList.add({"label":displayName,"value":displayName.replaceAll(" ","_")});
  29.   }
  30.  }
  31. }
  32. inputs = list();
  33. inputs.add({"type":"text","name":"task","label":"Task Name","hint":"Enter a subject","placeholder":"","min_length":8,"max_length":100,"mandatory":true});
  34. inputs.add({"type":"date","name":"date","label":"Due Date","placeholder":"Choose a due date","mandatory":false});
  35. modulesList = list();
  36. modulesList.add({"label":"Lead","value":"lead"});
  37. modulesList.add({"label":"Contact","value":"contacts"});
  38. inputs.add({"type":"select","name":"module","label":"Type of module","placeholder":"Choose a module","trigger_on_change":true,"options":modulesList});
  39. inputs.add({"type":"textarea","name":"description","label":"Description","hint":"Enter description","placeholder":"","min_length":0,"max_length":1000,"mandatory":false});​
  40. inputs.add({"type":"select","name":"priority","label":"Priority","placeholder":"Choose a priority","mandatory":false,"options":priorityList});
  41. inputs.add({"type":"select","name":"status","label":"Status","placeholder":"Choose a status","mandatory":false,"options":statusList});
  42. return {"type":"form","title":"Create a task","hint":"Name the task and assign a user","name":"createTask","button_label":"Create","actions":{"submit":{"type":"invoke.function","name":"createTask"}},"inputs":inputs};

Note : Make sure to replace the connection link name

Creating a connection:
  • Click on the connections button on the top right of the code editor.
  • Click on the Create Connection button
  • In default services, select the Zoho OAuth service and enable the following scopes:
    • ZohoCRM.modules.ALL
    • ZohoCRM.settings.ALL
  • Now authorize the connection

Step 2: Create a Form Function

 The second step is to create a form function that will handle the creation of the task in Zoho CRM. To do this, navigate to  Bots & Tools > Integrations > Functions > Create , and name your function " createTask ". Add a description and select the function type as form.

Then, paste the provided code in the form submit handler, which will handle the form submission and create a task in Zoho CRM.

  1. info form;
  2. paramsMap = map();
  3. labelList = list();
  4. formValues = form.get("values");
  5. module = formValues.get("module").get("label");
  6. subject = formValues.get("task");
  7. labelList.add({"Subject":subject});
  8. paramsMap.put("Subject", subject);
  9. description = formValues.get("description");
  10. if(description.length() > 0)
  11. {
  12.  labelList.add({"Description":description});
  13.  paramsMap.put("Description", description); 
  14. }
  15. dueDate = formValues.get("date");
  16. if(dueDate.length() > 0)
  17. {
  18.  dueDate = dueDate.toString("yyyy-MM-dd");
  19.  paramsMap.put("Due_Date", dueDate);
  20. }
  21. else 
  22. {
  23.  dueDate = "-";
  24. }
  25. labelList.add({"Due Date":dueDate});
  26. priority = formValues.get("priority");
  27. if(priority.keys().size() > 0)
  28. {
  29.  priority = priority.get("label");
  30.  paramsMap.put("Priority", priority);
  31. }
  32. else 
  33. {
  34.  priority = "High";
  35. }
  36. labelList.add({"Priority":priority});
  37. status = formValues.get("status");
  38. if(status.keys().size() > 0)
  39. {
  40.  status = status.get("label");
  41.  paramsMap.put("Status", status);
  42. }
  43. else 
  44. {
  45.  status = "Not Started";
  46. }
  47. labelList.add({"Status":status});
  48. if(module == "Lead")
  49. {
  50.  leadID = formValues.get("lead").get("value");
  51.  paramsMap.put("What_Id", leadID);
  52.  paramsMap.put("$se_module", "Leads");
  53.  labelList.add({"Lead":formValues.get("lead").get("label")});
  54. }
  55. else if(module == "Contact") 
  56. {
  57.  contactDetails = formValues.get("contact").keys();
  58.  if(contactDetails.size() > 0)
  59.  {
  60.   contactID = formValues.get("contact").get("value");
  61.   paramsMap.put("Who_Id", contactID);
  62.   labelList.add({"Contact":formValues.get("contact").get("label")});
  63.  }
  64.  assciatedModule = formValues.get("contactModule").get("value");
  65.  if(assciatedModule == "account")
  66.  {
  67.   choosenModule = "Accounts";
  68.  }
  69.  else 
  70.     {
  71.   choosenModule = "Deals";
  72.     }
  73.  accountOrDealID = formValues.get(assciatedModule).get("value");
  74.  paramsMap.put("What_Id", accountOrDealID);
  75.  paramsMap.put("$se_module", choosenModule);
  76.  labelList.add({choosenModule:formValues.get(assciatedModule).get("label")});
  77. }
  78. params = map();
  79. params.put("data", [paramsMap]);
  80. createTask = invokeurl
  81. [
  82.  url: "https://www.zohoapis.com/crm/v2/tasks"
  83.  type: POST
  84.  parameters: params+""
  85.  detailed : true
  86.  connection: "CONNECTION LINK NAME"
  87. ];
  88. info createTask;
  89. if(createTask.get("responseCode") == 201)
  90. {
  91.  response = {"text":"### Task has been created successfully 👍","card":{"theme":"10"},"slides":[{"type":"label","data":labelList}],"buttons":[{"label":"View","action":{"type":"open.url","data":{"web":"https://crm.zoho.com/crm/tab/Tasks/"+createTask.get("responseText").get("data").toMap().get("details").get("id")}}}]};
  92. }
  93. else 
  94. {
  95.  response = {"text":"Something went wrong with the integration. Please try again after some time!!!","type":"banner","status":"failure"};
  96. }
  97. return response;

Step 3: Update with Form Change Handler

The third step is to create a form change handler that will update the task details as the user fills out the form. To do this, navigate to the form change handler and paste the provided code in the script editor.

  1. targetName = target.get("name");
  2. info targetName;
  3. formValues = form.get("values");
  4. info formValues;
  5. actions = list();
  6. if(targetName == "module")
  7. {
  8.  modulesList = {"task","description","date","module","priority","status"};
  9.  allKeys = formValues.keys();
  10.  for each  key in allKeys
  11.  {
  12.   if(!modulesList.contains(key))
  13.   {
  14.    actions.add({"type":"remove","name":key});
  15.   }
  16.  }
  17.  fieldValue = formValues.get("module").keys();
  18.  if(fieldValue.size() > 0)
  19.  {
  20.   label = formValues.get("module").get("label");
  21.   if(label == "Lead")
  22.   {
  23.    leadsList = list();
  24.    getAllLeads = invokeurl
  25.    [
  26.     url :"https://www.zohoapis.com/crm/v2/leads"
  27.     type :GET
  28.     connection:"CONNECTION LINK NAME"
  29.    ];
  30.    leads = getAllLeads.get("data");
  31.    leadlist = List();
  32.    i = 0;
  33.    for each  lead in leads
  34.    {
  35.     if(i == 10)
  36.     {
  37.      break;
  38.     }
  39.     leadName = lead.get("Full_Name");
  40.     leadId = lead.get("id");
  41.     leadsList.add({"label":leadName,"value":leadId});
  42.     i = i + 1;
  43.    }
  44.    actions.add({"type":"add_after","name":"module","input":{"type":"dynamic_select","name":"lead","label":"Lead","hint":"Choose a lead","placeholder":"","mandatory":true,"options":leadsList}});
  45.   }
  46.   else if(label == "Contact")
  47.   {
  48.    contactsList = list();
  49.    getContacts = invokeurl
  50.    [
  51.     url :"https://www.zohoapis.com/crm/v2/Contacts"
  52.     type :GET
  53.     connection:"CONNECTION LINK NAME"
  54.    ];
  55.    info getContacts;
  56.    contacts = getContacts.get("data");
  57.    i = 0;
  58.    for each  contact in contacts
  59.    {
  60.     if(i == 10)
  61.     {
  62.      break;
  63.     }
  64.     contactName = contact.get("Full_Name");
  65.     contactID = contact.get("id");
  66.     contactsList.add({"label":contactName,"value":contactID});
  67.     i = i + 1;
  68.    }
  69.    actions.add({"type":"add_after","name":"module","input":{"type":"select","name":"contact","label":"Contact","hint":"Choose a contact","placeholder":"","mandatory":false,"options":contactsList,"trigger_on_change":true}});
  70.    contactModuleList = list();
  71.    contactModuleList.add({"label":"Account","value":"account"});
  72.    contactModuleList.add({"label":"Deal","value":"deal"});
  73.    actions.add({"type":"add_after","name":"contact","input":{"type":"select","name":"contactModule","label":"Associated Module","hint":"Choose a module","placeholder":"","mandatory":true,"options":contactModuleList,"trigger_on_change":true}});
  74.   }
  75.  }
  76. }
  77. else if(targetName == "contact")
  78. {
  79.  contactsList = {"task","description","date","module","contact","contactModule","priority","status"};
  80.  allKeys = formValues.keys();
  81.  for each  key in allKeys
  82.  {
  83.   if(!contactsList.contains(key))
  84.   {
  85.    actions.add({"type":"remove","name":key});
  86.   }
  87.  }
  88.  actions.add({"type":"clear","name":"contactModule"});
  89.  actions.add({"type":"clear","name":"deal"});
  90.  actions.add({"type":"clear","name":"account"});
  91. }
  92. else if(targetName == "contactModule")
  93. {
  94.  contactsList = {"task","description","date","module","contact","contactModule","priority","status"};
  95.  allKeys = formValues.keys();
  96.  for each  key in allKeys
  97.  {
  98.   if(!contactsList.contains(key))
  99.   {
  100.    actions.add({"type":"remove","name":key});
  101.   }
  102.  }
  103.  label = formValues.get("contactModule").keys();
  104.  if(label.size() > 0)
  105.  {
  106.   labelValue = formValues.get("contactModule").get("label");
  107.   if(labelValue == "Deal")
  108.   {
  109.    moduleName = "deals";
  110.   }
  111.   else if(labelValue == "Account")
  112.   {
  113.    moduleName = "accounts";
  114.   }
  115.   contactsKeys = formValues.get("contact").keys();
  116.   if(contactsKeys.size() > 0)
  117.   {
  118.    contactId = formValues.get("contact").get("value");
  119.    url = "https://www.zohoapis.com/crm/v2/Contacts/" + contactId + "/" + moduleName;
  120.   }
  121.   else
  122.   {
  123.    url = "https://www.zohoapis.com/crm/v2/" + moduleName;
  124.   }
  125.   getAllDetails = invokeurl
  126.   [
  127.    url :url
  128.    type :GET
  129.    connection:"CONNECTION LINK NAME"
  130.   ];
  131.   info getAllDetails;
  132.   details = getAllDetails.get("data");
  133.   if(!details.size() > 0)
  134.   {
  135.    url = "https://www.zohoapis.com/crm/v2/" + moduleName;
  136.    getAllDetails = invokeurl
  137.    [
  138.     url :url
  139.     type :GET
  140.     connection:"CONNECTION LINK NAME"
  141.    ];
  142.    info getAllDetails;
  143.    details = getAllDetails.get("data");
  144.   }
  145.   detailsList = list();
  146.   i = 0;
  147.   for each  detail in details
  148.   {
  149.    if(i == 10)
  150.    {
  151.     break;
  152.    }
  153.    if(labelValue == "Deal")
  154.    {
  155.     dealName = detail.get("Deal_Name");
  156.     dealID = detail.get("id");
  157.     detailsList.add({"label":dealName,"value":dealID});
  158.    }
  159.    else if(labelValue == "Account")
  160.    {
  161.     AccountName = detail.get("Account_Name");
  162.     AccountID = detail.get("id");
  163.     detailsList.add({"label":AccountName,"value":AccountID});
  164.    }
  165.    i = i + 1;
  166.   }
  167.   actions.add({"type":"add_after","name":"contactModule","input":{"type":"dynamic_select","name":labelValue.toLowerCase(),"label":labelValue.proper(),"hint":"","placeholder":"Select a " + labelValue,"mandatory":true,"options":detailsList}});
  168.  }
  169. }
  170. return {"type":"form_modification","actions":actions};

Step 4: Dynamic Handler

Now navigate to the Dynamic Handler and paste this code:

  1. info target;
  2. typeList = list();
  3. searchValue = target.get("query");
  4. formValues = form.get("values");
  5. if(target.get("name") == "lead")
  6. {
  7.  getLeads = invokeurl
  8.  [
  9.   url :"https://www.zohoapis.com/crm/v2/leads"
  10.   type :GET
  11.   connection:"CONNECTION LINK NAME"
  12.  ];
  13.  //info getLeads;
  14.  leads = getLeads.get("data");
  15.  for each  lead in leads
  16.  {
  17.   if(lead.containsIgnoreCase(searchValue))
  18.   {
  19.    if(typeList == 100)
  20.    {
  21.     break;
  22.    }
  23.    leadName = lead.get("Full_Name");
  24.    leadId = lead.get("id");
  25.    lead = {"label":leadName,"value":leadId};
  26.    typeList.add(lead);
  27.   }
  28.  }
  29. }
  30. else if(target.get("name") == "account")
  31. {
  32.  contactsKeys = formValues.get("contact").keys();
  33.  if(contactsKeys.size() > 0)
  34.  {
  35.   contactId = formValues.get("contact").get("value");
  36.   url = "https://www.zohoapis.com/crm/v2/Contacts/" + contactId + "/accounts";
  37.  }
  38.  else
  39.  {
  40.   url = "https://www.zohoapis.com/crm/v2/accounts";
  41.  }
  42.  getAccounts = invokeurl
  43.  [
  44.   url :url
  45.   type :GET
  46.   connection:"CONNECTION LINK NAME"
  47.  ];
  48.  //info getLeads;
  49.  accounts = getAccounts.get("data");
  50.  if(!accounts.size() > 0)
  51.  {
  52.   url = "https://www.zohoapis.com/crm/v2/accounts";
  53.   getAccounts = invokeurl
  54.   [
  55.    url :url
  56.    type :GET
  57.    connection:"CONNECTION LINK NAME"
  58.   ];
  59.  }
  60.  for each  account in accounts
  61.  {
  62.   if(account.containsIgnoreCase(searchValue))
  63.   {
  64.    if(typeList == 100)
  65.    {
  66.     break;
  67.    }
  68.    AccountName = account.get("Account_Name");
  69.    AccountID = account.get("id");
  70.    typeList.add({"label":AccountName,"value":AccountID});
  71.   }
  72.  }
  73. }
  74. else if(target.get("name") == "deal")
  75. {
  76.  contactsKeys = formValues.get("contact").keys();
  77.  if(contactsKeys.size() > 0)
  78.  {
  79.   contactId = formValues.get("contact").get("value");
  80.   url = "https://www.zohoapis.com/crm/v2/Contacts/" + contactId + "/deals";
  81.  }
  82.  else
  83.  {
  84.   url = "https://www.zohoapis.com/crm/v2/deals";
  85.  }
  86.  getDeals = invokeurl
  87.  [
  88.   url :url
  89.   type :GET
  90.   connection:"CONNECTION LINK NAME"
  91.  ];
  92.  deals = getDeals.get("data");
  93.  if(!deals.size() > 0)
  94.  {
  95.   url = "https://www.zohoapis.com/crm/v2/deals";
  96.   getDeals = invokeurl
  97.   [
  98.    url :url
  99.    type :GET
  100.    connection:"CONNECTION LINK NAME"
  101.   ];
  102.   deals = getDeals.get("data");
  103.  }
  104.  for each  deal in deals
  105.  {
  106.   if(deal.containsIgnoreCase(searchValue))
  107.   {
  108.    if(typeList == 100)
  109.    {
  110.     break;
  111.    }
  112.    dealName = deal.get("Deal_Name");
  113.    dealID = deal.get("id");
  114.    typeList.add({"label":dealName,"value":dealID});
  115.   }
  116.  }
  117. }
  118. return {"options":typeList};

Message Action

Besides the Command method, you can also use Message Actions to create a task in Zoho CRM directly from a chat. To do this, navigate to  Bots & Tools > Integrations > Message Action > Create , and create a new message action.

In the message action creation window, you will need to enter a name, description, and choose the access level. Then, paste the provided code in the script editor.

  1. description = message.get("text");
  2. if(description.length() >= 1000)
  3. {
  4.  description = description.subString(0,1000);
  5. }
  6. fetchFields = invokeurl
  7. [
  8.  url :"https://www.zohoapis.com/crm/v2/settings/fields?module=Tasks"
  9.  type :GET
  10.  connection:"CONNECTION LINK NAME"
  11. ];
  12. //info fetchFields;
  13. allFields = fetchFields.get("fields");
  14. priorityList = list();
  15. statusList = list();
  16. for each  field in allFields
  17. {
  18.  if(field.get("api_name") == "Priority")
  19.  {
  20.   pickListValues = field.get("pick_list_values");
  21.   for each  pickList in pickListValues
  22.   {
  23.    displayName = pickList.get("display_value");
  24.    priorityList.add({"label":displayName,"value":displayName.replaceAll(" ","_")});
  25.   }
  26.  }
  27.  else if(field.get("api_name") == "Status")
  28.  {
  29.   pickListValues = field.get("pick_list_values");
  30.   for each  pickList in pickListValues
  31.   {
  32.    displayName = pickList.get("display_value");
  33.    statusList.add({"label":displayName,"value":displayName.replaceAll(" ","_")});
  34.   }
  35.  }
  36. }
  37. inputs = list();
  38. inputs.add({"type":"text","name":"task","label":"Task Name","hint":"Enter a subject","placeholder":"","min_length":8,"max_length":100,"mandatory":true});
  39. inputs.add({"type":"textarea","name":"description","label":"Description","hint":"Enter description","placeholder":"","min_length":5,"max_length":1000,"mandatory":false,"value":description});
  40. inputs.add({"type":"date","name":"date","label":"Due Date","placeholder":"Choose a due date","mandatory":false});
  41. modulesList = list();
  42. modulesList.add({"label":"Lead","value":"lead"});
  43. modulesList.add({"label":"Contact","value":"contacts"});
  44. inputs.add({"type":"select","name":"module","label":"Type of module","placeholder":"Choose a module","trigger_on_change":true,"options":modulesList});
  45. inputs.add({"type":"select","name":"priority","label":"Priority","placeholder":"Choose a priority","mandatory":false,"options":priorityList});
  46. inputs.add({"type":"select","name":"status","label":"Status","placeholder":"Choose a status","mandatory":false,"options":statusList});
  47. return {"type":"form","title":"Create a task","hint":"Name the task and assign a user","name":"createTask","button_label":"Create","actions":{"submit":{"type":"invoke.function","name":"createTask"}},"inputs":inputs};

Note : Make sure to replace the connection link name
This code will create a message action that you can use to create a task in Zoho CRM. Once used on a message, the createTask function created earlier will handle the task creation process (and the message will automatically be entered as the task description).

In summary, by following these steps, users can create a task in Zoho CRM directly from a chat in Zoho Cliq using either Command or Message Action. This can save time and streamline the workflow for teams that use both Zoho Cliq and Zoho CRM.






                            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

                                        • Convert a message on Cliq into a task on Zoho Connect

                                          Message actions in Cliq are a great way to transform messages in a conversation into actionable work items. In this post, we'll see how to build a custom message action that'll let you add a message as a task to board on Zoho Connect. If you haven't created
                                        • Cliq Bots - Post message to a bot using the command line!

                                          If you had read our post on how to post a message to a channel in a simple one-line command, then this sure is a piece of cake for you guys! For those of you, who are reading this for the first time, don't worry! Just read on. This post is all about how
                                        • Cliq Bots - How to make a bot respond to your messages?

                                          Bots are just like your buddies with whom you can interact. They carry out your tasks, keep you notified about your to-dos and come in handy when you need constant updates from a third party application.  So, how can you make your bot respond to a message? The bot message handler is a piece of code triggered when a message is sent to the bot. Message handlers help you customise your bot responses to make it look conversational. The message input from the user can be either a string or an option selected
                                        • Cliq Bots - Get notifications about any action on an application with the incoming webhook handler!

                                          Webhooks can be used to get notified about events happening in other applications inside Cliq. All bots in Cliq have their own incoming webhook endpoint. This makes it simple to post messages to the bot from external applications. Unlike the send message
                                        • The Slash Command Series - Types of Command Suggestions

                                          Hi Everybody! I hope you guys tried the /zdocs command and now have an idea of how command suggestions with click to execute work. If you have no clue of what command suggestion is, I recommend you to take a look at all the Slash Command Series posts, especially the one on Command Suggestions ! This post is all about the different types of command suggestions.  Customise your command suggestions  Did you know you could customise your command suggestion list with a title, description, image? Well,


                                        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 WorkDrive Resources



                                                                  Zoho Campaigns Resources

                                                                    Zoho CRM Resources

                                                                    • CRM Community Learning Series

                                                                      CRM Community Learning Series


                                                                    • Tips

                                                                      Tips

                                                                    • 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