The capabilities of this custom function does not stop here. The goal is to fetch the employee details and add them to records in modules to indicate the record owner. For companies with a huge sales team, sometimes panning across products or branches, this custom function comes handy.
Getting started with the custom function:
- Go to Setup > Customization > Modules > Select the required module > Links and Buttons > +Create new button.
- Provide a name for the button. For example: “Add Record Owner information”. Add a description(optional).
- Choose View page from the drop-down list.
- Select Writing custom function from the subsequent drop-down.
- Provide a name for the custom function. Add a description(optional).
- Click “Free flow scripting”.
- Copy the code given below.
- Click “Edit arguments”.
- Enter the name as “leadId” and select the value as “Lead Id”.
- Save the changes.
- Change the 'xxxxxxxxxxxxxxxxx' with your crm authtoken .
- Click Save to create the button.
The script:
Code for Version 2.0 API:
Arguments :
record owner id - name it as 'ownerid'
record id - name it as 'leadId'
headerMap = {"Authorization":"555289a90fb486ea702236e516ac87b2"};
response = invokeurl
[
type :GET
headers:headerMap
];
//info response;
uservalue = response.get("users").toJSONList();
for each rec in uservalue
{
city = ifnull(rec.get("city"),"");
state = ifnull(rec.get("state"),"");
country = ifnull(rec.get("country"),"");
email = ifnull(rec.get("email"),"");
phone = ifnull(rec.get("phone"),"");
name = ifnull(rec.get("full_name"),"");
}
mp = Map();
mp.put("Owner's_City",city);
mp.put("Owner's_State",state);
mp.put("Owner's_Country",country);
mp.put("Owner's_Email",email);
mp.put("Owner's_Phone",phone);
mp.put("Owner's_Name",name);
update = zoho.crm.update("Leads",leadId.toLong(),mp);
info mp;
info update;
return "success";
Code for Version 1.0 API:
leadIdStr = input.leadId.toString();
loginemail= zoho.loginuserid ;
info userResp;
users = userResp.executeXPath("/users/user");
if ((users != null) && (users != ""))
{
userList = users.toList("-|-");
for each user in userList
{
emailNode = user.executeXPath("/user/@email");
email = emailNode.executeXPath("/email/text()");
if (email == loginemail)
{
idNode = user.executeXPath("/user/@phone");
phone = idNode.executeXPath("/phone/text()");
name = user.executeXPath("/user/text()");
email = emailNode.executeXPath("/email/text()");
}
}
}
mp=map();
mp.put("Owner's Name",name);
mp.put("Owner's Phone",phone);
mp.put("Owner's Email",email);
update=zoho.crm.updateRecord("Leads", leadIdStr, mp);
info mp;
info update;
return "success";
Note: