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
- In CRM, open the set up page, then go to modules and fields under customization
- Open your deals module, in my case it's called opportunities
- Open the layout you want to edit
- Add a user field and name it
- Save and close the module
- Then, on the setup, go to developer space and click on APIs
- On the top, go to APIs names and open "opportunities"
- On the list, find the field you just created, and take note of the API name
Part 2: Creating the function
- In the set up, click on "functions" under "developer space"
- Click on the "new function" button
- Name the function and select automation as the category
- Copy the code down below and paste it in the function body
- 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
- Replace "Sales_Support1" for the API name that you found on step one
- Replace "Task name - " with the name of the task you prefer
- 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"),"")]
- Replace the due date number with the number you want the task to be created at
- Replace the reminder number with the number you want the system sends a reminder
- Make sure the due date is after the reminder date, otherwise the reminder will not work
- 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
- Now click on edit arguments and map the argument "yourDealid" as an "int"
- 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
- In the setup page, click on workflow rules under automations
- Create a new rule, select the deals module, and name it
- Configure your workflow trigger and conditions:
- In my case we are going to do it on a record action > when the stage is modified to any value
- Condition: stage is "scheduled estimate"
- As the instant action, select "function"
- Click on "new function" and then select "functions"
- Find the function you just created, and click on "configure"
- Map the argument "yourDealid" as the deal ID, using the # key
- Test the workflow