View a contact's other open deals in a deal record

View all open deals associated with a contact while viewing another related deal record.

It's important to have visibility into a contact's underlying deals to prevent your salespeople from making mistakes like over-quoting, under-quoting, or double-quoting customers. As of today, you can only view ongoing and closed deals on a contact record. But what if you need to see all open deals associated with a contact while on another related deal record? Well, it's just a function away.

Our low-code tools enable you to retrieve and show all of a contact's open deals within a deal record. This way, you get the visibility of other ongoing deals your team is pursuing with that contact when you view their deal record. You just need to create a custom function and connect it to a new related list in the Deals module.


Solution by : Hugh Marshall, Square Labs

Permissions and availability

  • Users with the Manage Extensibility permission can write custom functions.
  • Users with the Modules Customization permission can add related lists.
  • Users with the Manage Sandbox permission can manage the sandbox.

Requirements

  • Write a custom function using Zoho's Deluge scripting language that fetches a contact's other open deals. Learn more
  • Add a related list within the deal details page and include the custom function to display other open deals. Learn more
  • Test the function in a sandbox environment before deploying it to your production environment. Learn more

Write a Custom Function

The first step is to write the custom function that will be linked to the related list.

  1. Go to Setup > Developer Space > Functions > +New Function.
  2. Provide a name and display name for the function. For example: "Other Open Deals". 
  3. Select the category of the function as Related List.
  4. Copy and paste the code provided below.
  5. Click Edit Arguments.
  6. Enter the parameter name as "dealId" and select the type as "string".
  7. Click Save.
Write Custom Function

The code

Code Copied
//Get deal information
dealMap = zoho.crm.getRecordById("Deals",dealId);

//Get contact
contact = dealMap.get("Contact_Name");

//Check whether the contact is associated to the deal
if(!isnull(contact))
{
	//Get the contact ID
	contactId = contact.get("id");

	//Get all deals associated with the contact
	relatedDeals = zoho.crm.getRelatedRecords("Deals","Contacts",contactId);

	//Prepare the related deals list with applicable filters
	openRelatedDeals = List();

	//Exclude the currently viewed deal and any closed deals and add other deals to the list
	for each deal in relatedDeals
	{
		if(deal.get("id") != dealId && !deal.get("Stage").contains("Closed"))
		{
			openRelatedDeals.add(deal);
		}
	}

	//Check if there is at least 1 open deal before proceeding
	if(openRelatedDeals.size() > 0)
	{
		//Prepare the XML
		rowVal = 0;
		responseXML = "";
		responseXML = responseXML + "<record>";
		for each openDeal in openRelatedDeals
		{
			responseXML = responseXML + "<row no='" + rowVal + "'>";
			responseXML = responseXML + "<FL link='true' url='<<INSERT ZOHO CRM DEALS URL HERE>>" + openDeal.get("id") + "' val='Deal Name'>" + openDeal.get("Deal_Name") + "</FL>";
			responseXML = responseXML + "<FL val='Stage'>" + openDeal.get("Stage") + "</FL>";
			responseXML = responseXML + "<FL val='Closing Date'>" + openDeal.get("Closing_Date") + "</FL>";
			responseXML = responseXML + "<FL val='Amount'>$" + openDeal.get("Amount") + "</FL>";
			responseXML = responseXML + "</row>";
			rowVal = rowVal + 1;
		}
		//End the XML
		responseXML = responseXML + "</record>";
	}
	else
	{
		//Input the message to be displayed if there are no other open deals for the contact
		responseXML = "<error><message>No Other Open Deals</message></error>";
	}
}
else
{
	//Input the message to be displayed if there are no contacts associated with the deal
	responseXML = "<error><message>No Contact Associated to this Deal</message></error>";
}
info responseXML;
return responseXML;

Notes

  • Paste the Zoho CRM Deals page URL in the above code snippet—for example, https://crm.zoho.com/crm/org123456789/tab/Potentials/.
  • Make sure to use the accurate API names for their corresponding fields in the code snippet. Learn more

Add a related list

The final step is to add a related list to the deal details page to display a contact's other open deals.

  1. Open a deal record to view its details.
  2. Go to the Related List panel on the left and click the Add Related List option.
  3. Select Functions in the pop-up window.
  4. Select Add Now, corresponding to the function you created in the previous steps.
  5. Specify a name for the related list. For example: "Other Open Deals". 
  6. Press # to fetch the merge field and map the argument as dealId = Deals > Deal Id.
  7. Click Save.

Tip

  • Click the Reorder icon to move the Other Open Deals list to a specific location on the deal details page.

Test the solution

  1. Go to the Deals module and click on the desired deal. 
  2. On the Deal Details page, look for the Other Open Deals related list section. It will display information about the contact's other open deals.

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

  • ModuleDeals
  • Trigger PointRelated List
  • EditionEnterprise and above
  • ComplexityMedium
  • Implementation Time30 minutes

Features used in the solution

Deluge ScriptRelated ListSandbox
Story Image

Looking for a custom solution?

Contact us, we will help enhance your productivity at lightning speed.

SUBMIT REQUEST

Developers: Share your solution with our community!