For Zoho Services only:


I'm actually part of something bigger at Ascent Business Solutions recognized as the top Zoho Premium Solutions Partner in the United Kingdom.

Ascent Business Solutions offer support for smaller technical fixes and projects for larger developments, such as migrating to a ZohoCRM.  A team rather than a one-man-band is always available to ensure seamless progress and address any concerns. You'll find our competitive support rates with flexible, no-expiration bundles at https://ascentbusiness.co.uk/zoho-services/uk-zoho-support.  For larger projects, talk to our experts and receive dedicated support from our hands-on project consultants at https://ascentbusiness.co.uk/zoho-services/zoho-crm-implementation.

The team I manage specializes in coding API integrations between Zoho and third-party finance/commerce suites such as Xero, Shopify, WooCommerce, and eBay; to name but a few.  Our passion lies in creating innovative solutions where others have fallen short as well as working with new businesses, new sectors, and new ideas.  Our success is measured by the growth and ROI we deliver for clients, such as transforming a garden shed hobby into a 250k monthly turnover operation or generating a +60% return in just three days after launch through online payments and a streamlined e-commerce solution, replacing a paper-based system.

If you're looking for a partner who can help you drive growth and success, we'd love to work with you.  You can reach out to us on 0121 392 8140 (UK) or info@ascentbusiness.co.uk.  You can also visit our website at https://ascentbusiness.co.uk.

Zoho CRM & Zoho Books: Custom Related Lists Deluge

What?
This is an article to quickly demo a couple of snippets of code to display values in a custom related list as well as to display empty custom related lists.

Why?
Because I keep forgetting how to do this and it takes about an hour to go through the documentation and get a working solution.

How?
So the article below shows how to do this Zoho CRM and how to do it in Zoho Books...

The example below is that we are going to search for some records in Zoho Creator and display these in either Zoho Books or Zoho CRM. For demonstration purposes, these have been simplified and will need to be adapted for your needs. Note that I have used 2 URL methods of linking to the Creator app and some data formatting that I tend to use regularly for my benefit later on when I simply copy & paste the below code templates.

Zoho CRM
copyraw
//
// initialize
v_Index = 0;
//
// search in Creator
v_OwnerName = <AppOwner>;
v_AppLinkName = <AppName>;
v_FormLinkName = <FormName>;
v_ViewLinkName = <ReportName>;
v_Condition = "(Opportunities==\"" + v_DealID + "\")&&(UpdateClick==\"Yes\")";
r_SearchResults = zoho.creator.getRecords(v_OwnerName,v_AppLinkName,v_ViewLinkName,v_Condition,1,100,"joels_connection");
v_ResponseCode = ifnull(r_SearchResults.get("code"),500).toLong();
//
// if found records
if(v_ResponseCode == 3000)
{
	v_RelatedListXML = "<record>";
	l_SearchResults = r_SearchResults.get("data").toJSONList();
	for each  r_Result in l_SearchResults
	{
		// init
		v_DateTill= "-";
		v_QuoteTotalDisp= "-";
		v_Index = v_Index + 1;
		v_RelatedListXML = v_RelatedListXML + "<row no=\"" + v_Index + "\">";
		//
		// retrieve
		v_CreatorQuoteID = r_Result.get("ID");
		v_LinkUrl2 = "https://creatorapp.zoho.eu/" + v_OwnerName + "/" + v_AppLinkName + "/#Page:OpenQuote?ID=" + v_CreatorQuoteID;
		v_QuoteRef = ifnull(r_Result.get("Quote_Ref"),"-");
		v_QuoteName = ifnull(r_Result.get("Quote_Name"),"-");
		v_QuoteStage = ifnull(r_Result.get("Quote_Stage"),"-");
		v_QuoteCurr = ifnull(r_Result.get("Quote_Currency"),"GBP");
		v_QuoteTotal = ifnull(r_Result.get("Total_Amount"),0.0).toDecimal();
		v_ExchangeRate = ifnull(r_Result.get("Exchange_Rate"),1);
		v_ModifiedTime = ifnull(r_Result.get("Modified_Time"),r_Result.get("Added_Time")).toTime().toString("dd/MM/yyyy hh:mm a");
		//
		// future proofs
		v_ExchangeRate = if(v_ExchangeRate == 0,1,v_ExchangeRate);
		// 
		// transforms
		if(r_Result.get("Valid_Till") != null)
		{
			v_DateTill = r_Result.get("Valid_Until").toDate().toString("dd/MM/yyyy");
		}
		if(v_QuoteTotal != 0)
		{
			v_QuoteTotalGBP = (v_QuoteTotal.toDecimal() / v_ExchangeRate).toDecimal().round(2);
			//
			// format currency with commas (thousand separator) and 2 decimals
			v_QuoteTotalStr = v_QuoteTotal.toDecimal().round(2).toString().replaceAll("(?<!\.\d)(?<=\d)(?=(?:\d\d\d)+\b)",",");
			v_QuoteTotalGBPStr = v_QuoteTotalGBP.toDecimal().round(2).toString().replaceAll("(?<!\.\d)(?<=\d)(?=(?:\d\d\d)+\b)",",");
			//
			// to display both side by side if different otherwise display GBP
			if(!isnull(m_Currencies.get(v_QuoteCurr)))
			{
				if(v_QuoteCurr == "GBP")
				{
					v_QuoteTotalDisp = m_Currencies.get(v_QuoteCurr) + " " + v_QuoteTotalGBPStr;
				}
				else
				{
					v_QuoteTotalDisp = m_Currencies.get(v_QuoteCurr) + " " + v_QuoteTotalStr + " (£ " + v_QuoteTotalGBPStr + ")";
				}
			}
			else
			{
				v_QuoteTotalDisp = v_QuoteTotalStr + " " + v_QuoteCurr + " (£ " + v_QuoteTotalGBPStr + ")";
			}
		}
		v_RelatedListXML = v_RelatedListXML + "<FL val=\"Quote Ref\">" + v_QuoteRef + "</FL>";
		// don't forget to escape quote name with CDATA in case of XML banned characters
		v_RelatedListXML = v_RelatedListXML + "<FL val=\"Quote Name\" link=\"true\" url=\"" + v_LinkUrl2 + "\"><![CDATA[" + v_QuoteName + "]]></FL>";
		v_RelatedListXML = v_RelatedListXML + "<FL val=\"Valid Till\">" + v_DateTill + "</FL>";
		v_RelatedListXML = v_RelatedListXML + "<FL val=\"Stage\">" + v_QuoteStage + "</FL>";
		v_RelatedListXML = v_RelatedListXML + "<FL val=\"Total Amount\">" + v_QuoteTotalDisp + "</FL>";
		v_RelatedListXML = v_RelatedListXML + "<FL val=\"Modified Time\">" + v_ModifiedTime + "</FL>";
		v_RelatedListXML = v_RelatedListXML + "</row>";
		v_Index = v_Index + 1;
	}
	v_RelatedListXML = v_RelatedListXML + "</record>";
}
else
{
	// display "no records found"
	v_RelatedListXML = "<error><message>";
	v_RelatedListXML = v_RelatedListXML + "No records found";
	v_RelatedListXML = v_RelatedListXML + "</message></error>";
}
//
// output
return v_RelatedListXML;
  1.  // 
  2.  // initialize 
  3.  v_Index = 0
  4.  // 
  5.  // search in Creator 
  6.  v_OwnerName = <AppOwner>
  7.  v_AppLinkName = <AppName>
  8.  v_FormLinkName = <FormName>
  9.  v_ViewLinkName = <ReportName>
  10.  v_Condition = "(Opportunities==\"" + v_DealID + "\")&&(UpdateClick==\"Yes\")"
  11.  r_SearchResults = zoho.creator.getRecords(v_OwnerName,v_AppLinkName,v_ViewLinkName,v_Condition,1,100,"joels_connection")
  12.  v_ResponseCode = ifnull(r_SearchResults.get("code"),500).toLong()
  13.  // 
  14.  // if found records 
  15.  if(v_ResponseCode == 3000) 
  16.  { 
  17.      v_RelatedListXML = "<record>"
  18.      l_SearchResults = r_SearchResults.get("data").toJSONList()
  19.      for each  r_Result in l_SearchResults 
  20.      { 
  21.          // init 
  22.          v_DateTill= "-"
  23.          v_QuoteTotalDisp= "-"
  24.          v_Index = v_Index + 1
  25.          v_RelatedListXML = v_RelatedListXML + "<row no=\"" + v_Index + "\">"
  26.          // 
  27.          // retrieve 
  28.          v_CreatorQuoteID = r_Result.get("ID")
  29.          v_LinkUrl2 = "https://creatorapp.zoho.eu/" + v_OwnerName + "/" + v_AppLinkName + "/#Page:OpenQuote?ID=" + v_CreatorQuoteID; 
  30.          v_QuoteRef = ifnull(r_Result.get("Quote_Ref"),"-")
  31.          v_QuoteName = ifnull(r_Result.get("Quote_Name"),"-")
  32.          v_QuoteStage = ifnull(r_Result.get("Quote_Stage"),"-")
  33.          v_QuoteCurr = ifnull(r_Result.get("Quote_Currency"),"GBP")
  34.          v_QuoteTotal = ifnull(r_Result.get("Total_Amount"),0.0).toDecimal()
  35.          v_ExchangeRate = ifnull(r_Result.get("Exchange_Rate"),1)
  36.          v_ModifiedTime = ifnull(r_Result.get("Modified_Time"),r_Result.get("Added_Time")).toTime().toString("dd/MM/yyyy hh:mm a")
  37.          // 
  38.          // future proofs 
  39.          v_ExchangeRate = if(v_ExchangeRate == 0,1,v_ExchangeRate)
  40.          // 
  41.          // transforms 
  42.          if(r_Result.get("Valid_Till") != null) 
  43.          { 
  44.              v_DateTill = r_Result.get("Valid_Until").toDate().toString("dd/MM/yyyy")
  45.          } 
  46.          if(v_QuoteTotal != 0) 
  47.          { 
  48.              v_QuoteTotalGBP = (v_QuoteTotal.toDecimal() / v_ExchangeRate).toDecimal().round(2)
  49.              // 
  50.              // format currency with commas (thousand separator) and 2 decimals 
  51.              v_QuoteTotalStr = v_QuoteTotal.toDecimal().round(2).toString().replaceAll("(?<!\.\d)(?<=\d)(?=(?:\d\d\d)+\b)",",")
  52.              v_QuoteTotalGBPStr = v_QuoteTotalGBP.toDecimal().round(2).toString().replaceAll("(?<!\.\d)(?<=\d)(?=(?:\d\d\d)+\b)",",")
  53.              // 
  54.              // to display both side by side if different otherwise display GBP 
  55.              if(!isnull(m_Currencies.get(v_QuoteCurr))) 
  56.              { 
  57.                  if(v_QuoteCurr == "GBP") 
  58.                  { 
  59.                      v_QuoteTotalDisp = m_Currencies.get(v_QuoteCurr) + " " + v_QuoteTotalGBPStr; 
  60.                  } 
  61.                  else 
  62.                  { 
  63.                      v_QuoteTotalDisp = m_Currencies.get(v_QuoteCurr) + " " + v_QuoteTotalStr + (£ " + v_QuoteTotalGBPStr + ")"
  64.                  } 
  65.              } 
  66.              else 
  67.              { 
  68.                  v_QuoteTotalDisp = v_QuoteTotalStr + " " + v_QuoteCurr + (£ " + v_QuoteTotalGBPStr + ")"
  69.              } 
  70.          } 
  71.          v_RelatedListXML = v_RelatedListXML + "<FL val=\"Quote Ref\">" + v_QuoteRef + "</FL>"
  72.          // don't forget to escape quote name with CDATA in case of XML banned characters 
  73.          v_RelatedListXML = v_RelatedListXML + "<FL val=\"Quote Name\" link=\"true\" url=\"" + v_LinkUrl2 + "\"><![CDATA[" + v_QuoteName + "]]></FL>"
  74.          v_RelatedListXML = v_RelatedListXML + "<FL val=\"Valid Till\">" + v_DateTill + "</FL>"
  75.          v_RelatedListXML = v_RelatedListXML + "<FL val=\"Stage\">" + v_QuoteStage + "</FL>"
  76.          v_RelatedListXML = v_RelatedListXML + "<FL val=\"Total Amount\">" + v_QuoteTotalDisp + "</FL>"
  77.          v_RelatedListXML = v_RelatedListXML + "<FL val=\"Modified Time\">" + v_ModifiedTime + "</FL>"
  78.          v_RelatedListXML = v_RelatedListXML + "</row>"
  79.          v_Index = v_Index + 1
  80.      } 
  81.      v_RelatedListXML = v_RelatedListXML + "</record>"
  82.  } 
  83.  else 
  84.  { 
  85.      // display "no records found" 
  86.      v_RelatedListXML = "<error><message>"
  87.      v_RelatedListXML = v_RelatedListXML + "No records found"
  88.      v_RelatedListXML = v_RelatedListXML + "</message></error>"
  89.  } 
  90.  // 
  91.  // output 
  92.  return v_RelatedListXML; 

in Zoho Books
copyraw
//
// find all related quotes
l_DataRows = List();
v_QuoteRefID = "0";
v_CrmOppID = "0";
v_OwnerName = <AppOwner>;
v_AppLinkName = <AppName>;
v_FormLinkName = <FormName>;
v_ViewLinkName = <ReportName>;
if(!isnull(salesorder.get("salesorder_id")))
{
	v_CreatorSoID = salesorder.get("salesorder_id");
}
v_SearchCriteria = "Sales_Order_ID==\"" + v_CreatorSoID + "\"";
r_SearchResults = zoho.creator.getRecords(v_OwnerName,v_AppLinkName,v_ViewLinkName,v_SearchCriteria,1,100,"joels_connnection");
v_ResponseCode = ifnull(r_SearchResults.get("code"),500).toLong();
if(v_ResponseCode == 3000)
{
	l_HeaderColumns = List();
	l_HeaderColumns.add({"key":"quote_name","value":"Name"});
	l_HeaderColumns.add({"key":"valid_till","value":"Valid Till"});
	l_HeaderColumns.add({"key":"quote_status","value":"Quote Status"});
	l_SearchResults = r_SearchResults.get("data").toJSONList();
	for each  r_Result in l_SearchResults
	{
		v_CreatorQuoteID = r_Result.get("ID");
		m_DataRow = Map();
		m_LinkedValue = Map();
		m_LinkedValue.put("value",r_Result.get("Quote_Name"));
		m_LinkedValue.put("isExternal",true);
		m_LinkedValue.put("link","https://app.zohocreator.eu/"+v_OwnerName+"/"+v_AppLinkName+"/"+v_FormLinkName+"/record-edit/"+v_ViewLinkName+"/"+v_CreatorQuoteID+"?param1=my_param_value");
		v_DateTill = "-";
		if(!isnull(r_Result.get("Valid_Till")))
		{
			v_DateTill = r_Result.get("Valid_Till").toDate().toString("dd/MM/yyyy");
		}
		m_DataRow.put("quote_name",m_LinkedValue);
		m_DataRow.put("valid_till",v_DateTill);
		m_DataRow.put("quote_status",r_Result.get("Quote_Status"));
		l_DataRows.add(m_DataRow);
	}
}
else
{
	l_HeaderColumns = List();
	l_HeaderColumns.add({"key":"message","value":"Message"});
	//
	if(v_ResponseCode == 3100)
	{
		m_DataRow = Map();
		m_DataRow.put("message","No records found");
		l_DataRows.add(m_DataRow);
	}
	else
	{
		m_DataRow = Map();
		m_DataRow.put("message",r_SearchResults.get("message") + " :: " + v_ResponseCode);
		l_DataRows.add(m_DataRow);
	}
}
//
m_RelatedList = Map();
m_RelatedList.put("header_context",l_HeaderColumns);
m_RelatedList.put("data",l_DataRows);
return m_RelatedList;
  1.  // 
  2.  // find all related quotes 
  3.  l_DataRows = List()
  4.  v_QuoteRefID = "0"
  5.  v_CrmOppID = "0"
  6.  v_OwnerName = <AppOwner>
  7.  v_AppLinkName = <AppName>
  8.  v_FormLinkName = <FormName>
  9.  v_ViewLinkName = <ReportName>
  10.  if(!isnull(salesorder.get("salesorder_id"))) 
  11.  { 
  12.      v_CreatorSoID = salesorder.get("salesorder_id")
  13.  } 
  14.  v_SearchCriteria = "Sales_Order_ID==\"" + v_CreatorSoID + "\""
  15.  r_SearchResults = zoho.creator.getRecords(v_OwnerName,v_AppLinkName,v_ViewLinkName,v_SearchCriteria,1,100,"joels_connnection")
  16.  v_ResponseCode = ifnull(r_SearchResults.get("code"),500).toLong()
  17.  if(v_ResponseCode == 3000) 
  18.  { 
  19.      l_HeaderColumns = List()
  20.      l_HeaderColumns.add({"key":"quote_name","value":"Name"})
  21.      l_HeaderColumns.add({"key":"valid_till","value":"Valid Till"})
  22.      l_HeaderColumns.add({"key":"quote_status","value":"Quote Status"})
  23.      l_SearchResults = r_SearchResults.get("data").toJSONList()
  24.      for each  r_Result in l_SearchResults 
  25.      { 
  26.          v_CreatorQuoteID = r_Result.get("ID")
  27.          m_DataRow = Map()
  28.          m_LinkedValue = Map()
  29.          m_LinkedValue.put("value",r_Result.get("Quote_Name"))
  30.          m_LinkedValue.put("isExternal",true)
  31.          m_LinkedValue.put("link","https://app.zohocreator.eu/"+v_OwnerName+"/"+v_AppLinkName+"/"+v_FormLinkName+"/record-edit/"+v_ViewLinkName+"/"+v_CreatorQuoteID+"?param1=my_param_value")
  32.          v_DateTill = "-"
  33.          if(!isnull(r_Result.get("Valid_Till"))) 
  34.          { 
  35.              v_DateTill = r_Result.get("Valid_Till").toDate().toString("dd/MM/yyyy")
  36.          } 
  37.          m_DataRow.put("quote_name",m_LinkedValue)
  38.          m_DataRow.put("valid_till",v_DateTill)
  39.          m_DataRow.put("quote_status",r_Result.get("Quote_Status"))
  40.          l_DataRows.add(m_DataRow)
  41.      } 
  42.  } 
  43.  else 
  44.  { 
  45.      l_HeaderColumns = List()
  46.      l_HeaderColumns.add({"key":"message","value":"Message"})
  47.      // 
  48.      if(v_ResponseCode == 3100) 
  49.      { 
  50.          m_DataRow = Map()
  51.          m_DataRow.put("message","No records found")
  52.          l_DataRows.add(m_DataRow)
  53.      } 
  54.      else 
  55.      { 
  56.          m_DataRow = Map()
  57.          m_DataRow.put("message",r_SearchResults.get("message") + :: " + v_ResponseCode)
  58.          l_DataRows.add(m_DataRow)
  59.      } 
  60.  } 
  61.  // 
  62.  m_RelatedList = Map()
  63.  m_RelatedList.put("header_context",l_HeaderColumns)
  64.  m_RelatedList.put("data",l_DataRows)
  65.  return m_RelatedList; 

Error(s) Encountered
  • Sorry, there was a problem processing your request.: Your returned XML is invalid
  • Sorry, there is a tag discrepancy in the function. The related list cannot be displayed.: You are trying to return <record> </record> (an empty record dataset).


Category: Zoho :: Article: 756

Credit where Credit is Due:


Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.

Disclaimer: Please note that the information provided on this website is intended for informational purposes only and does not represent a warranty. The opinions expressed are those of the author only. We recommend testing any solutions in a development environment before implementing them in production. The articles are based on our good faith efforts and were current at the time of writing, reflecting our practical experience in a commercial setting.

Thank you for visiting and, as always, we hope this website was of some use to you!

Kind Regards,

Joel Lipman
www.joellipman.com

Related Articles

Joes Revolver Map

Accreditation

Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Paypal:
Donate to Joel Lipman via PayPal

Bitcoin:
Donate to Joel Lipman with Bitcoin bc1qf6elrdxc968h0k673l2djc9wrpazhqtxw8qqp4

Ethereum:
Donate to Joel Lipman with Ethereum 0xb038962F3809b425D661EF5D22294Cf45E02FebF
© 2024 Joel Lipman .com. All Rights Reserved.