Assign task automatically to user field in Zoho CRM

07.18.21 11:53 AM By Andy

In this tutorial we are going to create a workflow that will assign a task to a user that is not the record owner. In the example we will work on the Opportunities module (deals), and will create a function that is going to create and assign a task to the user that is selected in the Sales Support field.

Part 1: Add a user field to your layout

  1. In CRM, open the set up page, then go to modules and fields under customization
  2. Open your deals module, in my case it's called opportunities
  3. Open the layout you want to edit
  4. Add a user field and name it
  5. Save and close the module
  6. Then, on the setup, go to developer space and click on APIs
  7. On the top, go to APIs names and open "opportunities"
  8. On the list, find the field you just created, and take note of the API name


Part 2: Creating the function

  1. In the set up, click on "functions" under "developer space"
  2. Click on the "new function" button
  3. Name the function and select automation as the category
  4. Copy the code down below and paste it in the function body
    1. You will see that some texts are grey; they are clarifications that explain each part of the function in case you need to edit it
  5. Replace "Sales_Support1" for the API name that you found on step one
  6. Replace "Task name - " with the name of the task you prefer
    1. The second part of this like is going to add the deal name to the task name, but you can removed this if you prefer [+ ifnull(dealDetails.get("Deal_Name"),"")]
  7. Replace the due date number with the number you want the task to be created at
  8. Replace the reminder number with the number you want the system sends a reminder
    1. Make sure the due date is after the reminder date, otherwise the reminder will not work
    2. If you don't want to set a reminder, you can remove the line completely, as well as the section marked in blue in the code
  9. Now click on edit arguments and map the argument "yourDealid" as an "int"
  10. Finally save the arguments and save the function
dealDetails = zoho.crm.getRecordById("Deals",yourDealid);
//find the sales support id related to the deal
SalesSupport = ifnull(dealDetails.get("Sales_Support1"),"").get("id");
//name the task combining get colors plus dial name
taskSubject = "Task name - " + ifnull(dealDetails.get("Deal_Name"),"");
//due date is 6 day after the task is created
dueDate = today.addDay(6);
//reminder 5 days after the task is created
reminderTime = today.addDay(5).toTime();
//creating the task
taskMap = Map();
taskMap.put("$se_module","Deals");
taskMap.put("What_Id",yourDealid);
taskMap.put("Owner",SalesSupport);
taskMap.put("Subject",taskSubject);
taskMap.put("Due_Date",dueDate);
//reminder via email
taskMap.put("Remind_At",{"ALARM":"FREQ=NONE;ACTION=EMAIL;TRIGGER=DATE-TIME:" + reminderTime.toString("yyyy-MM-dd'T'HH:mm:ss'+05:30'")});
taskMap.put("Status","Not Started");
taskMap.put("Send_Notification_Email",true);
createResp = zoho.crm.createRecord("Tasks",taskMap);
info taskMap;
info createResp;

Part 3: Creating the workflow

  1. In the setup page, click on workflow rules under automations
  2. Create a new rule, select the deals module, and name it
  3. Configure your workflow trigger and conditions:
    1. In my case we are going to do it on a record action > when the stage is modified to any value
    2. Condition: stage is "scheduled estimate"
  4. As the instant action, select "function"
  5. Click on "new function" and then select "functions"
  6. Find the function you just created, and click on "configure"
  7. Map the argument "yourDealid" as the deal ID, using the # key
  8. Test the workflow