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:
- fetchFields = invokeurl
- [
- url :"https://www.zohoapis.com/crm/v2/settings/fields?module=Tasks"
- type :GET
- connection:"CONNECTION LINK NAME"
- ];
- //info fetchFields;
- allFields = fetchFields.get("fields");
- priorityList = list();
- statusList = list();
- for each field in allFields
- {
- if(field.get("api_name") == "Priority")
- {
- pickListValues = field.get("pick_list_values");
- for each pickList in pickListValues
- {
- displayName = pickList.get("display_value");
- priorityList.add({"label":displayName,"value":displayName.replaceAll(" ","_")});
- }
- }
- else if(field.get("api_name") == "Status")
- {
- pickListValues = field.get("pick_list_values");
- for each pickList in pickListValues
- {
- displayName = pickList.get("display_value");
- statusList.add({"label":displayName,"value":displayName.replaceAll(" ","_")});
- }
- }
- }
- inputs = list();
- inputs.add({"type":"text","name":"task","label":"Task Name","hint":"Enter a subject","placeholder":"","min_length":8,"max_length":100,"mandatory":true});
- inputs.add({"type":"date","name":"date","label":"Due Date","placeholder":"Choose a due date","mandatory":false});
- modulesList = list();
- modulesList.add({"label":"Lead","value":"lead"});
- modulesList.add({"label":"Contact","value":"contacts"});
- inputs.add({"type":"select","name":"module","label":"Type of module","placeholder":"Choose a module","trigger_on_change":true,"options":modulesList});
- inputs.add({"type":"textarea","name":"description","label":"Description","hint":"Enter description","placeholder":"","min_length":0,"max_length":1000,"mandatory":false});
- inputs.add({"type":"select","name":"priority","label":"Priority","placeholder":"Choose a priority","mandatory":false,"options":priorityList});
- inputs.add({"type":"select","name":"status","label":"Status","placeholder":"Choose a status","mandatory":false,"options":statusList});
- 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.
- info form;
- paramsMap = map();
- labelList = list();
- formValues = form.get("values");
- module = formValues.get("module").get("label");
- subject = formValues.get("task");
- labelList.add({"Subject":subject});
- paramsMap.put("Subject", subject);
- description = formValues.get("description");
- if(description.length() > 0)
- {
- labelList.add({"Description":description});
- paramsMap.put("Description", description);
- }
- dueDate = formValues.get("date");
- if(dueDate.length() > 0)
- {
- dueDate = dueDate.toString("yyyy-MM-dd");
- paramsMap.put("Due_Date", dueDate);
- }
- else
- {
- dueDate = "-";
- }
- labelList.add({"Due Date":dueDate});
- priority = formValues.get("priority");
- if(priority.keys().size() > 0)
- {
- priority = priority.get("label");
- paramsMap.put("Priority", priority);
- }
- else
- {
- priority = "High";
- }
- labelList.add({"Priority":priority});
- status = formValues.get("status");
- if(status.keys().size() > 0)
- {
- status = status.get("label");
- paramsMap.put("Status", status);
- }
- else
- {
- status = "Not Started";
- }
- labelList.add({"Status":status});
- if(module == "Lead")
- {
- leadID = formValues.get("lead").get("value");
- paramsMap.put("What_Id", leadID);
- paramsMap.put("$se_module", "Leads");
- labelList.add({"Lead":formValues.get("lead").get("label")});
- }
- else if(module == "Contact")
- {
- contactDetails = formValues.get("contact").keys();
- if(contactDetails.size() > 0)
- {
- contactID = formValues.get("contact").get("value");
- paramsMap.put("Who_Id", contactID);
- labelList.add({"Contact":formValues.get("contact").get("label")});
- }
- assciatedModule = formValues.get("contactModule").get("value");
- if(assciatedModule == "account")
- {
- choosenModule = "Accounts";
- }
- else
- {
- choosenModule = "Deals";
- }
- accountOrDealID = formValues.get(assciatedModule).get("value");
- paramsMap.put("What_Id", accountOrDealID);
- paramsMap.put("$se_module", choosenModule);
- labelList.add({choosenModule:formValues.get(assciatedModule).get("label")});
- }
- params = map();
- params.put("data", [paramsMap]);
- createTask = invokeurl
- [
- url: "https://www.zohoapis.com/crm/v2/tasks"
- type: POST
- parameters: params+""
- detailed : true
- connection: "CONNECTION LINK NAME"
- ];
- info createTask;
- if(createTask.get("responseCode") == 201)
- {
- 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")}}}]};
- }
- else
- {
- response = {"text":"Something went wrong with the integration. Please try again after some time!!!","type":"banner","status":"failure"};
- }
- 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.
- targetName = target.get("name");
- info targetName;
- formValues = form.get("values");
- info formValues;
- actions = list();
- if(targetName == "module")
- {
- modulesList = {"task","description","date","module","priority","status"};
- allKeys = formValues.keys();
- for each key in allKeys
- {
- if(!modulesList.contains(key))
- {
- actions.add({"type":"remove","name":key});
- }
- }
- fieldValue = formValues.get("module").keys();
- if(fieldValue.size() > 0)
- {
- label = formValues.get("module").get("label");
- if(label == "Lead")
- {
- leadsList = list();
- getAllLeads = invokeurl
- [
- url :"https://www.zohoapis.com/crm/v2/leads"
- type :GET
- connection:"CONNECTION LINK NAME"
- ];
- leads = getAllLeads.get("data");
- leadlist = List();
- i = 0;
- for each lead in leads
- {
- if(i == 10)
- {
- break;
- }
- leadName = lead.get("Full_Name");
- leadId = lead.get("id");
- leadsList.add({"label":leadName,"value":leadId});
- i = i + 1;
- }
- actions.add({"type":"add_after","name":"module","input":{"type":"dynamic_select","name":"lead","label":"Lead","hint":"Choose a lead","placeholder":"","mandatory":true,"options":leadsList}});
- }
- else if(label == "Contact")
- {
- contactsList = list();
- getContacts = invokeurl
- [
- url :"https://www.zohoapis.com/crm/v2/Contacts"
- type :GET
- connection:"CONNECTION LINK NAME"
- ];
- info getContacts;
- contacts = getContacts.get("data");
- i = 0;
- for each contact in contacts
- {
- if(i == 10)
- {
- break;
- }
- contactName = contact.get("Full_Name");
- contactID = contact.get("id");
- contactsList.add({"label":contactName,"value":contactID});
- i = i + 1;
- }
- 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}});
- contactModuleList = list();
- contactModuleList.add({"label":"Account","value":"account"});
- contactModuleList.add({"label":"Deal","value":"deal"});
- 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}});
- }
- }
- }
- else if(targetName == "contact")
- {
- contactsList = {"task","description","date","module","contact","contactModule","priority","status"};
- allKeys = formValues.keys();
- for each key in allKeys
- {
- if(!contactsList.contains(key))
- {
- actions.add({"type":"remove","name":key});
- }
- }
- actions.add({"type":"clear","name":"contactModule"});
- actions.add({"type":"clear","name":"deal"});
- actions.add({"type":"clear","name":"account"});
- }
- else if(targetName == "contactModule")
- {
- contactsList = {"task","description","date","module","contact","contactModule","priority","status"};
- allKeys = formValues.keys();
- for each key in allKeys
- {
- if(!contactsList.contains(key))
- {
- actions.add({"type":"remove","name":key});
- }
- }
- label = formValues.get("contactModule").keys();
- if(label.size() > 0)
- {
- labelValue = formValues.get("contactModule").get("label");
- if(labelValue == "Deal")
- {
- moduleName = "deals";
- }
- else if(labelValue == "Account")
- {
- moduleName = "accounts";
- }
- contactsKeys = formValues.get("contact").keys();
- if(contactsKeys.size() > 0)
- {
- contactId = formValues.get("contact").get("value");
- url = "https://www.zohoapis.com/crm/v2/Contacts/" + contactId + "/" + moduleName;
- }
- else
- {
- url = "https://www.zohoapis.com/crm/v2/" + moduleName;
- }
- getAllDetails = invokeurl
- [
- url :url
- type :GET
- connection:"CONNECTION LINK NAME"
- ];
- info getAllDetails;
- details = getAllDetails.get("data");
- if(!details.size() > 0)
- {
- url = "https://www.zohoapis.com/crm/v2/" + moduleName;
- getAllDetails = invokeurl
- [
- url :url
- type :GET
- connection:"CONNECTION LINK NAME"
- ];
- info getAllDetails;
- details = getAllDetails.get("data");
- }
- detailsList = list();
- i = 0;
- for each detail in details
- {
- if(i == 10)
- {
- break;
- }
- if(labelValue == "Deal")
- {
- dealName = detail.get("Deal_Name");
- dealID = detail.get("id");
- detailsList.add({"label":dealName,"value":dealID});
- }
- else if(labelValue == "Account")
- {
- AccountName = detail.get("Account_Name");
- AccountID = detail.get("id");
- detailsList.add({"label":AccountName,"value":AccountID});
- }
- i = i + 1;
- }
- 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}});
- }
- }
- return {"type":"form_modification","actions":actions};
Step 4: Dynamic Handler
Now navigate to the Dynamic Handler and paste this code:
- info target;
- typeList = list();
- searchValue = target.get("query");
- formValues = form.get("values");
- if(target.get("name") == "lead")
- {
- getLeads = invokeurl
- [
- url :"https://www.zohoapis.com/crm/v2/leads"
- type :GET
- connection:"CONNECTION LINK NAME"
- ];
- //info getLeads;
- leads = getLeads.get("data");
- for each lead in leads
- {
- if(lead.containsIgnoreCase(searchValue))
- {
- if(typeList == 100)
- {
- break;
- }
- leadName = lead.get("Full_Name");
- leadId = lead.get("id");
- lead = {"label":leadName,"value":leadId};
- typeList.add(lead);
- }
- }
- }
- else if(target.get("name") == "account")
- {
- contactsKeys = formValues.get("contact").keys();
- if(contactsKeys.size() > 0)
- {
- contactId = formValues.get("contact").get("value");
- url = "https://www.zohoapis.com/crm/v2/Contacts/" + contactId + "/accounts";
- }
- else
- {
- url = "https://www.zohoapis.com/crm/v2/accounts";
- }
- getAccounts = invokeurl
- [
- url :url
- type :GET
- connection:"CONNECTION LINK NAME"
- ];
- //info getLeads;
- accounts = getAccounts.get("data");
- if(!accounts.size() > 0)
- {
- url = "https://www.zohoapis.com/crm/v2/accounts";
- getAccounts = invokeurl
- [
- url :url
- type :GET
- connection:"CONNECTION LINK NAME"
- ];
- }
- for each account in accounts
- {
- if(account.containsIgnoreCase(searchValue))
- {
- if(typeList == 100)
- {
- break;
- }
- AccountName = account.get("Account_Name");
- AccountID = account.get("id");
- typeList.add({"label":AccountName,"value":AccountID});
- }
- }
- }
- else if(target.get("name") == "deal")
- {
- contactsKeys = formValues.get("contact").keys();
- if(contactsKeys.size() > 0)
- {
- contactId = formValues.get("contact").get("value");
- url = "https://www.zohoapis.com/crm/v2/Contacts/" + contactId + "/deals";
- }
- else
- {
- url = "https://www.zohoapis.com/crm/v2/deals";
- }
- getDeals = invokeurl
- [
- url :url
- type :GET
- connection:"CONNECTION LINK NAME"
- ];
- deals = getDeals.get("data");
- if(!deals.size() > 0)
- {
- url = "https://www.zohoapis.com/crm/v2/deals";
- getDeals = invokeurl
- [
- url :url
- type :GET
- connection:"CONNECTION LINK NAME"
- ];
- deals = getDeals.get("data");
- }
- for each deal in deals
- {
- if(deal.containsIgnoreCase(searchValue))
- {
- if(typeList == 100)
- {
- break;
- }
- dealName = deal.get("Deal_Name");
- dealID = deal.get("id");
- typeList.add({"label":dealName,"value":dealID});
- }
- }
- }
- 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.
- description = message.get("text");
- if(description.length() >= 1000)
- {
- description = description.subString(0,1000);
- }
- fetchFields = invokeurl
- [
- url :"https://www.zohoapis.com/crm/v2/settings/fields?module=Tasks"
- type :GET
- connection:"CONNECTION LINK NAME"
- ];
- //info fetchFields;
- allFields = fetchFields.get("fields");
- priorityList = list();
- statusList = list();
- for each field in allFields
- {
- if(field.get("api_name") == "Priority")
- {
- pickListValues = field.get("pick_list_values");
- for each pickList in pickListValues
- {
- displayName = pickList.get("display_value");
- priorityList.add({"label":displayName,"value":displayName.replaceAll(" ","_")});
- }
- }
- else if(field.get("api_name") == "Status")
- {
- pickListValues = field.get("pick_list_values");
- for each pickList in pickListValues
- {
- displayName = pickList.get("display_value");
- statusList.add({"label":displayName,"value":displayName.replaceAll(" ","_")});
- }
- }
- }
- inputs = list();
- inputs.add({"type":"text","name":"task","label":"Task Name","hint":"Enter a subject","placeholder":"","min_length":8,"max_length":100,"mandatory":true});
- inputs.add({"type":"textarea","name":"description","label":"Description","hint":"Enter description","placeholder":"","min_length":5,"max_length":1000,"mandatory":false,"value":description});
- inputs.add({"type":"date","name":"date","label":"Due Date","placeholder":"Choose a due date","mandatory":false});
- modulesList = list();
- modulesList.add({"label":"Lead","value":"lead"});
- modulesList.add({"label":"Contact","value":"contacts"});
- inputs.add({"type":"select","name":"module","label":"Type of module","placeholder":"Choose a module","trigger_on_change":true,"options":modulesList});
- inputs.add({"type":"select","name":"priority","label":"Priority","placeholder":"Choose a priority","mandatory":false,"options":priorityList});
- inputs.add({"type":"select","name":"status","label":"Status","placeholder":"Choose a status","mandatory":false,"options":statusList});
- 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.