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.
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 :: Article: 893

Add comment

Your rating:

Submit

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

Please publish modules in offcanvas position.