Notify Task owners on change of ownership.

Tasks help organize and manage your sales routines efficiently. Your sales routine might include a set number of tasks. Let's say the prospecting process of all your inbound leads includes 2 tasks - analyzing requirements, sending a quotation. This is followed up by a call. By default, all these activities are assigned to a sales executive who is the lead owner. When this sales executive goes on an unplanned leave, the sales manager reallocates the above tasks to another sales executive. However, the sales person to whom the tasks were originally assigned, remains the lead owner and he/she is expected to resume the process from follow-up call.

By design, when the task is reassigned, all the related emails are sent to the new task owner and there are no in-product alerts to notify the lead owner either. You don't want to leave the lead owner in the dark about the task reassignment, do you? Using this week's custom function, keep the original task owner (the lead owner in this case) notified about the task reassignment with a customized email. This custom function gets triggered whenever the task owner and the one to create the task are different.

Further, you can set a workflow rule in CRM so that whenever the task moves on to the next stage, the original owner of the task gets notified. This helps track the tasks progression. This flexibility ensures all your sales routines are completed seamlessly.

Getting started with the function:

  1. Go to Setup > Automation > Actions > Functions > Configure Function > Write your own.
  2. Provide a name for the function. For example: "Invoice Grand Total". Add a description(optional).
  3. Select the module to be associated asInvoice.
  4. Copy the code given below.
  5. Click "Edit arguments".
  6. Enter the name as "invoiceId" and select the value as "Invoice Id".
  7. Click Save & Execute Script.
  8. Save the changes.

 

The Code: For V1 API - Old Editor:

taskDetails = zoho.crm._getRecordById("Tasks", input.taskId);
info taskDetails;
taskowner = ifnull(taskDetails.get("Task Owner"),"");
info taskowner;
taskcreated = ifnull(taskDetails.get("Created By"),"");
info taskcreated;
userResp = getUrl(("https://crm.zoho.com/crm/private/xml/Users/getUsers?authtoken=79808ac37f504b5ab578745f1c45096a&scope=crmapi&type=ActiveUsers"));
info userResp;
users = userResp.executeXPath("/users/user");
if ((users != null) && (users != ""))
{
userList = users.toList("-|-");
for each user in userList
{
name = user.executeXPath("/user/text()");
if (name == taskcreated)
{
info name;
emailNode = user.executeXPath("/user/@email");
email = emailNode.executeXPath("/email/text()");
info email;
}
}
}
if ( taskowner != taskcreated )
{
link = "<a href='https://crm.zoho.com/crm/EntityInfo.do?module=Tasks&id=" + taskId + "' >Task Record</a>";
sendmail
[
from: zoho.adminuserid
to: email
subject: "Email Notification"
message: "Task ownership has been changed for the " + link + " . Do check the " + link + "id for more. "
]
}

The Code: For V2 API - DRE Editor:

taskDetails = zoho.crm.getRecordById("Tasks", input.taskId);
ownerid = ifnull(taskDetails.get("Owner"),"").get("id");
taskowner = ifnull(taskDetails.get("Owner"),"").get("name");
taskcreated = ifnull(taskDetails.get("Created_By"),"").get("name");
headerMap = {"Authorization":"555289a90fb486ea702236e516ac87b2"};
response = invokeurl
[
url :"https://crm.zoho.com/crm/v2/users/" +ownerid
type :GET
headers:headerMap
];
//info response;
uservalue = response.get("users").toJSONList();
for each rec in uservalue
{
email = ifnull(rec.get("email"),"");
}
if ( taskowner != taskcreated )
{
link = "<a href='https://crm.zoho.com/crm/EntityInfo.do?module=Tasks&id=" + taskId + "' >Task Record</a>";
sendmail
[
from: zoho.adminuserid
to: email
subject: "Email Notification"
message: "Task ownership has been changed for the " + link + " . Do
check the " + link + "id for more. " ]
}

Note:

  • The code is zoho.crm._getRecordById for Version 1.0 of.
  • Change the email address in the 'emailNode' with the address of the task owner.
  • The above code can be used in conjunction with workflow rules. For example: Everytime the task status is changes, you can send a notification to the task owner.

Found this useful? Try it out and let me know how it works! If you have questions, do not hesitate to ask! Share this with your team if you find it useful!

Return to Tips