For Zoho services only


I'm currently part of a wider delivery team at Ascent Business Solutions, recognised as a leading Zoho Premium Solutions Partner in the United Kingdom.

Ascent Business Solutions support organisations with everything from targeted technical fixes through to full Zoho CRM implementations and long-term platform adoption. Working as a team rather than a one-person consultancy allows projects to move forward consistently, with access to the right skills at each stage.

The team I manage specialises in API integrations between Zoho and third-party finance and commerce platforms such as Xero, Shopify, WooCommerce, and eBay. Much of our work involves solving integration challenges that fall outside standard documentation, supporting new ideas, new sectors, and evolving business models.

Success is measured through practical outcomes and return on investment, ranging from scaling small operations into high-turnover businesses to delivering rapid gains through online payments, automation, and streamlined digital workflows.

If you are looking for structured Zoho expertise backed by an established consultancy, you can contact Ascent Business Solutions on 0121 392 8140 (UK), email info@ascentbusiness.co.uk, or visit https://www.ascentbusiness.co.uk.
ZohoCRM GetRelatedRecords INVALID_DATA

ZohoCRM GetRelatedRecords INVALID_DATA

What?
A ridiculously quick article on resolving a zoho.crm.getRelatedRecords() combined with a zoho.crm.bulkUpdate issue.

Why?
Trying to be clever and reducing the API calls to go through a few thousand records and to update the related records. I was getting the error INVALID_DATA with the details being api_name:'data'... But this is shortcode, not an invokeURL.

{ "code":"INVALID_DATA", "details":{ "api_name":"data" }, "message":"invalid data", "status":"error" }


How?
I recall covering this solution before but it boils simply down to the zoho.crm.getRelatedRecords() not retrieving related records which are clearly visible when using the CRM.

The cause of the problem is the same as covered in my article Joel Lipman - ZohoCRM: zoho.crm.searchRecords only returns certain records.

Consider the following code:

copyraw
/* *******************************************************************************
Function:       string standalone.fn_Deal_UpdateRelatedToCancelled()
Label:          Fn - Customer Deals - Cancel Related Records
Trigger:        Standalone
Purpose:		For any deal which is cancelled, cancel its related sales orders.
Inputs:         -
Outputs:        -

Date Created:   2025-01-30 (Joel Lipman)
				- Initial release
Date Modified:	???
				???

More Information:
				Custom View ID: 123456000012345678

******************************************************************************* */
//
// initialize
v_CountTotal = 0;
v_CountUpdated = 0;
l_Pages = {1};
v_PerPage = 1;
//
for each  v_Page in l_Pages
{
	l_Deals = zoho.crm.getRecords("Deals", v_Page, v_PerPage, {"cvid":123456000012345678});
	for each m_Deal in l_Deals
	{
		if(!isNull(m_Deal.get("id")))
		{
			v_CountTotal = v_CountTotal + 1;
			if(m_Deal.get("Stage").equalsIgnoreCase("Cancelled"))
			{
				//
				// cancel all related quotes
				// (...)
				//
				// cancel all related sales orders
				l_RelatedSOs = zoho.crm.getRelatedRecords("SalesOrders", "Deals", m_Deal.get("id"));
				l_UpdateSOs = List();
				for each m_SO in l_RelatedSOs
				{
					m_UpdateSO = {"id":m_SO.get("id"), "Status":"Cancelled"};
					l_UpdateSOs.add(m_UpdateSO);
				}
				r_UpdateRelated = zoho.crm.bulkUpdate("Sales_Orders", l_UpdateSOs);
				//
				// cancel all related invoices
				// (...)
				//
				// mark the deal as processed
				r_UpdateDeal = zoho.crm.updateRecord("Deals", m_Deal.get("id"), {"Cancelled_Related_Records":true}, {"trigger":{}});
				if(!isNull(r_UpdateDeal.get("id")))
				{
					v_CountUpdated = v_CountUpdated + 1;
				}
			}
		}
	}
}
  1.  /* ******************************************************************************* 
  2.  Function:       string standalone.fn_Deal_UpdateRelatedToCancelled() 
  3.  Label:          Fn - Customer Deals - Cancel Related Records 
  4.  Trigger:        Standalone 
  5.  Purpose:        For any deal which is cancelled, cancel its related sales orders. 
  6.  Inputs:         - 
  7.  Outputs:        - 
  8.   
  9.  Date Created:   2025-01-30 (Joel Lipman) 
  10.                  - Initial release 
  11.  Date Modified:    ??? 
  12.                  ??? 
  13.   
  14.  More Information: 
  15.                  Custom View ID: 123456000012345678 
  16.   
  17.  ******************************************************************************* */ 
  18.  // 
  19.  // initialize 
  20.  v_CountTotal = 0
  21.  v_CountUpdated = 0
  22.  l_Pages = {1}
  23.  v_PerPage = 1
  24.  // 
  25.  for each  v_Page in l_Pages 
  26.  { 
  27.      l_Deals = zoho.crm.getRecords("Deals", v_Page, v_PerPage, {"cvid":123456000012345678})
  28.      for each m_Deal in l_Deals 
  29.      { 
  30.          if(!isNull(m_Deal.get("id"))) 
  31.          { 
  32.              v_CountTotal = v_CountTotal + 1
  33.              if(m_Deal.get("Stage").equalsIgnoreCase("Cancelled")) 
  34.              { 
  35.                  // 
  36.                  // cancel all related quotes 
  37.                  // (...) 
  38.                  // 
  39.                  // cancel all related sales orders 
  40.                  l_RelatedSOs = zoho.crm.getRelatedRecords("SalesOrders", "Deals", m_Deal.get("id"))
  41.                  l_UpdateSOs = List()
  42.                  for each m_SO in l_RelatedSOs 
  43.                  { 
  44.                      m_UpdateSO = {"id":m_SO.get("id"), "Status":"Cancelled"}
  45.                      l_UpdateSOs.add(m_UpdateSO)
  46.                  } 
  47.                  r_UpdateRelated = zoho.crm.bulkUpdate("Sales_Orders", l_UpdateSOs)
  48.                  // 
  49.                  // cancel all related invoices 
  50.                  // (...) 
  51.                  // 
  52.                  // mark the deal as processed 
  53.                  r_UpdateDeal = zoho.crm.updateRecord("Deals", m_Deal.get("id"), {"Cancelled_Related_Records":true}, {"trigger":{}})
  54.                  if(!isNull(r_UpdateDeal.get("id"))) 
  55.                  { 
  56.                      v_CountUpdated = v_CountUpdated + 1
  57.                  } 
  58.              } 
  59.          } 
  60.      } 
  61.  } 


Corrected Code:

copyraw
/* *******************************************************************************
Function:       string standalone.fn_Deal_UpdateRelatedToCancelled()
Label:          Fn - Customer Deals - Cancel Related Records
Trigger:        Standalone
Purpose:		For any deal which is cancelled, cancel its related sales orders.
Inputs:         -
Outputs:        -

Date Created:   2025-01-30 (Joel Lipman)
				- Initial release
Date Modified:	???
				???

More Information:
				Custom View ID: 123456000012345678

******************************************************************************* */
//
// initialize
v_CountTotal = 0;
v_CountUpdated = 0;
l_Pages = {1};
v_PerPage = 1;
//
// map to retrieve all records (to include approved and converted records, this needs to be specified as the query value)
m_IgnoreRestrictions = Map();
m_IgnoreRestrictions.put("approved","both");
m_IgnoreRestrictions.put("converted","both");
//
for each  v_Page in l_Pages
{
	l_Deals = zoho.crm.getRecords("Deals", v_Page, v_PerPage, {"cvid":123456000012345678});
	for each m_Deal in l_Deals
	{
		if(!isNull(m_Deal.get("id")))
		{
			v_CountTotal = v_CountTotal + 1;
			if(m_Deal.get("Stage").equalsIgnoreCase("Cancelled"))
			{
				//
				// cancel all related quotes
				// (...)
				//
				// cancel all related sales orders (including those that have been approved or converted)
				l_RelatedSOs = zoho.crm.getRelatedRecords("SalesOrders", "Deals", m_Deal.get("id"), 1, 200, m_IgnoreRestrictions);
				l_UpdateSOs = List();
				for each m_SO in l_RelatedSOs
				{
					m_UpdateSO = {"id":m_SO.get("id"), "Status":"Cancelled"};
					l_UpdateSOs.add(m_UpdateSO);
				}
				r_UpdateRelated = zoho.crm.bulkUpdate("Sales_Orders", l_UpdateSOs);
				//
				// cancel all related invoices
				// (...)
				//
				// mark the deal as processed
				r_UpdateDeal = zoho.crm.updateRecord("Deals", m_Deal.get("id"), {"Cancelled_Related_Records":true}, {"trigger":{}});
				if(!isNull(r_UpdateDeal.get("id")))
				{
					v_CountUpdated = v_CountUpdated + 1;
				}
			}
		}
	}
}
  1.  /* ******************************************************************************* 
  2.  Function:       string standalone.fn_Deal_UpdateRelatedToCancelled() 
  3.  Label:          Fn - Customer Deals - Cancel Related Records 
  4.  Trigger:        Standalone 
  5.  Purpose:        For any deal which is cancelled, cancel its related sales orders. 
  6.  Inputs:         - 
  7.  Outputs:        - 
  8.   
  9.  Date Created:   2025-01-30 (Joel Lipman) 
  10.                  - Initial release 
  11.  Date Modified:    ??? 
  12.                  ??? 
  13.   
  14.  More Information: 
  15.                  Custom View ID: 123456000012345678 
  16.   
  17.  ******************************************************************************* */ 
  18.  // 
  19.  // initialize 
  20.  v_CountTotal = 0
  21.  v_CountUpdated = 0
  22.  l_Pages = {1}
  23.  v_PerPage = 1
  24.  // 
  25.  // map to retrieve all records (to include approved and converted records, this needs to be specified as the query value) 
  26.  m_IgnoreRestrictions = Map()
  27.  m_IgnoreRestrictions.put("approved","both")
  28.  m_IgnoreRestrictions.put("converted","both")
  29.  // 
  30.  for each  v_Page in l_Pages 
  31.  { 
  32.      l_Deals = zoho.crm.getRecords("Deals", v_Page, v_PerPage, {"cvid":123456000012345678})
  33.      for each m_Deal in l_Deals 
  34.      { 
  35.          if(!isNull(m_Deal.get("id"))) 
  36.          { 
  37.              v_CountTotal = v_CountTotal + 1
  38.              if(m_Deal.get("Stage").equalsIgnoreCase("Cancelled")) 
  39.              { 
  40.                  // 
  41.                  // cancel all related quotes 
  42.                  // (...) 
  43.                  // 
  44.                  // cancel all related sales orders (including those that have been approved or converted) 
  45.                  l_RelatedSOs = zoho.crm.getRelatedRecords("SalesOrders", "Deals", m_Deal.get("id"), 1, 200, m_IgnoreRestrictions)
  46.                  l_UpdateSOs = List()
  47.                  for each m_SO in l_RelatedSOs 
  48.                  { 
  49.                      m_UpdateSO = {"id":m_SO.get("id"), "Status":"Cancelled"}
  50.                      l_UpdateSOs.add(m_UpdateSO)
  51.                  } 
  52.                  r_UpdateRelated = zoho.crm.bulkUpdate("Sales_Orders", l_UpdateSOs)
  53.                  // 
  54.                  // cancel all related invoices 
  55.                  // (...) 
  56.                  // 
  57.                  // mark the deal as processed 
  58.                  r_UpdateDeal = zoho.crm.updateRecord("Deals", m_Deal.get("id"), {"Cancelled_Related_Records":true}, {"trigger":{}})
  59.                  if(!isNull(r_UpdateDeal.get("id"))) 
  60.                  { 
  61.                      v_CountUpdated = v_CountUpdated + 1
  62.                  } 
  63.              } 
  64.          } 
  65.      } 
  66.  } 


Source(s):

 

Category: Zoho CRM :: Article: 420

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