In today's competitive sales landscape, success depends heavily on the efficiency of internal processes and the visibility that sales managers have into their teams' activities.
For example, let's say a sales manager receives an unexpected call from a prospect. Without having immediate visibility into which sales rep is handling that lead—their contact details, location, and role—the manager may struggle to provide meaningful assistance or effectively address any escalations.
This operational challenge becomes even more pronounced in organizations with large, distributed sales teams that span multiple products, territories, or branches. The lack of readily available ownership information in lead records creates blind spots that can slow response times, complicate reporting, and hinder strategic decision-making. Fortunately, there's a solution!
A custom button—powered by a Deluge function—can automatically enrich lead records with comprehensive owner information, including city, state, email, and phone number—all with just a click of a button. Beyond identifying the owner, this solution enables sales managers to classify leads by assigned handlers, generate reports by sales rep profiles, and maintain complete visibility across their sales operations. Ultimately, this contributes to faster deal closures and improved customer satisfaction. Interested? Read on to learn more.
Permissions and availability
- Users with the Manage Extensibility permission can create connections and write custom functions.
- Users with the Modules Customization permission can add custom fields and buttons.
- Users with the Manage Sandbox permission can manage the sandbox.
Requirements
- Create a Zoho CRM connection with all the requisite scopes, as detailed in the "Create a Connection" section below. Learn more
- Add single-line fields in the Leads module that will hold values corresponding to sales reps from the Users module. Learn more
- Create and link the button with the custom function, as detailed in the "Create a Button" section below. Learn more
- Test the function in a sandbox before deploying it in your production environment. Learn more
Create a connection
The first step is to create a connection in your Zoho CRM account.
- Go to Setup > Developer Hub > Connections.
- Click CreateConnection.
- Select Zoho CRM under Default Services.
- Specify a Connection Name.
You will need to enter this name in the code snippet below. - Select the following Scopes to request access:
- ZohoCRM.modules.ALL
- ZohoCRM.users.ALL
- Click Create and Connect.
- Click Connect, then click Accept to confirm access to the requested scopes.
Add custom fields
Next, add single-line fields to the Leads module to store their owner information.
- Navigate to Setup > Customization > Modules and Fields.
- Click the Leads module to open the layout editor.
- Drag and drop six single-line fields from the New Fields tray to the desired section of the layout.
- Name the single-line fields (e.g., Owner Name, Owner Email, Owner Phone, etc.), define their properties as required, then click Done.
- Once you've finished, click Save and Close.
Create a button
Next, add a custom button that, when clicked, updates the lead owner's contact information in the lead record's corresponding fields.
- Navigate to Setup > Customization > Modules and Fields > Leads > Buttons > Create New Button.
- Provide a name for the button. For example: "Update Owner Info".
- Add a description (optional).
- Set the action to be performed as Function.
- Select the button's page and position as "In Record" and "Details," respectively.
- Choose the layouts in which you want the button to be placed.
- Click Choose to configure a function and select Write your own.
- Provide names for both the display and the function, then click Create.
- In the Deluge Script Editor, do the following:
- Copy and paste the code provided below.
- Click Edit Arguments.
- Enter the name as leadId, select the value as Leads - Lead Id.
- Click the + icon to add more arguments.
- Enter the name as ownerid, select the value as Leads - Lead Owner ID, then click Save.
- Save the function.
- Turn on button accessibility for CRM Users.
- Select the profiles that can view this custom button.
- Click Save.
The code
response = invokeurl
[
url :"https://crm.zoho.com/crm/v8/users/" + ownerid
type :GET
connection:"connectionname"
];
//info response;
uservalue = response.get("users").toJSONList();
for each rec in uservalue
{
name = ifnull(rec.get("full_name"),"");
email = ifnull(rec.get("email"),"");
phone = ifnull(rec.get("phone"),"");
city = ifnull(rec.get("city"),"");
state = ifnull(rec.get("state"),"");
country = ifnull(rec.get("country"),"");
}
mp = Map();
mp.put("Owner_Name",name);
mp.put("Owner_Email",email);
mp.put("Owner_Phone",phone);
mp.put("Owner_City",city);
mp.put("Owner_State",state);
mp.put("Owner_Country",country);
dlist = List();
dlist.add(mp);
dmp = Map();
dmp.put("data",dlist);
update = invokeurl
[
url :"https://www.zohoapis.com/crm/v8/Leads/" + leadId
type :PUT
parameters:dmp + ""
connection:"connectionname"
];
info update;
return "Success";Notes
- Make sure to use accurate API names for their corresponding fields (e.g., "Owner Name") in the code snippet. Learn more
- Replace "connectionname" with the name of the connection you specified when creating it (see the "Create a connection" section above).
- Change the URL endpoint to match your account's data center. For example, https://www.zohoapis.in/... for India.
- You can modify the script to add or remove owner fields as necessary.
- The button can be placed in different positions (Create, Edit, or List page) based on your workflow.
- The script above automatically populates lead owners' contact information into the custom fields of their lead records at the click of a button. You can use this code for other modules by modifying the module name, field names, and relevant parameters to suit your requirements.
Tip
- Configure and test the solution in a sandbox to ensure that further development doesn't disrupt your production environment.
Test the solution
- Navigate to the Leads module.
- Open a lead record to view its details.
- Confirm that the custom fields for owner information are available and empty.
- Click the button you added in the top-right corner.
- Wait for the success message to appear.
- Refresh the page and check whether all owner fields are populated with:
- Owner's full name
- Owner's phone number
- Owner's email address
- Owner's city, state, and country
- Test with different lead records owned by various users to ensure consistency.
Did you find this useful? Try it out and let us know how it works. Share this with your team if they'd benefit from it! If you have questions, please don't hesitate to contact us.
More info
- ModuleLeads
- Trigger PointCustom Button
- EditionEnterprise and above
- ComplexityHigh
- Implementation Time60 minutes

Looking for a custom solution?
Contact us, we will help enhance your productivity at lightning speed.
SUBMIT REQUEST