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 Deluge: Duplicate/Clone a Record

What?
This is an article with the snippet of code required to duplicate or clone a record in Zoho CRM using Zoho Deluge.

Why?
The aim here is to have a scheduled task that on the 1st of every month, takes the invoices for the month before, and duplicates each one for the new month.

How?
First you have to get all the applicable fields from the settings API. In API v2, you have to do it this way apparently. So setup a Zoho Oauth connector (see the end of this article if you don't know how), I'm going to call mine myZohoConnector, with the scope:
copyraw
ZohoCRM.settings.fields.READ
  1.  ZohoCRM.settings.fields.READ 
Then check your URL is correct. The format for API v2 is:
copyraw
https://www.zohoapis.{eu or com}/crm/v2/settings/fields?module={module-name}
  1.  https://www.zohoapis.{eu or com}/crm/v2/settings/fields?module={module-name} 
You can then use the following snippet to get all the fields for the module. In our case, for "Invoices":
copyraw
/*
Function: fn_Button_CloneInvoice
Purpose: This function duplicates a CRM invoice
Parameters: p_InvoiceID (CRM ID of the invoice)
Returns: Nothing

Author: Joel Lipman
Date Created: 2020-03-17
*/

// get all field names for the Invoices module via API
l_FieldApiNames = List();
r_Fields = invokeurl
[
	url :"https://www.zohoapis.eu/crm/v2/settings/fields?module=Invoices"
	type :GET
	connection:"myzohoconnector"
];
if(!isnull(r_Fields.get("fields")))
{
	for each  r_Field in r_Fields.get("fields")
	{
		l_FieldApiNames.add(r_Field.get("api_name"));
	}
}

// get details of original invoice
r_Invoice = zoho.crm.getRecordById("Invoices", p_InvoiceID);

// start map
m_Clone = Map();

// loop through field names
for each  v_FieldName in l_FieldApiNames
{
	if(!isNull(r_Invoice.get(v_FieldName)))
	{
		m_Clone.put(v_FieldName,r_Invoice.get(v_FieldName));
	}
}

// now override fields specific to the newly cloned/duplicated record
m_Clone.put("Invoice_Status","Repeated Invoice");
m_Clone.put("Invoice_Date",zoho.currentdate.toString("yyyy-MM-dd"));
m_Clone.put("Due_Date",zoho.currentdate.addMonth(1).toStartOfMonth().subDay(1).toString("yyyy-MM-dd"));

// create the record
r_Clone = zoho.crm.createRecord("Invoices",m_Clone);

// get cloned invoice ID
if(!isNull(r_Clone.get("id")))
{
	v_Duplicate_InvoiceID = r_Clone.get("id");
}
  1.  /* 
  2.  Function: fn_Button_CloneInvoice 
  3.  Purpose: This function duplicates a CRM invoice 
  4.  parameters: p_InvoiceID (CRM ID of the invoice) 
  5.  Returns: Nothing 
  6.   
  7.  Author: Joel Lipman 
  8.  Date Created: 2020-03-17 
  9.  */ 
  10.   
  11.  // get all field names for the Invoices module via API 
  12.  l_FieldApiNames = List()
  13.  r_Fields = invokeUrl 
  14.  [ 
  15.      url :"https://www.zohoapis.eu/crm/v2/settings/fields?module=Invoices" 
  16.      type :GET 
  17.      connection:"myzohoconnector" 
  18.  ]
  19.  if(!isnull(r_Fields.get("fields"))) 
  20.  { 
  21.      for each  r_Field in r_Fields.get("fields") 
  22.      { 
  23.          l_FieldApiNames.add(r_Field.get("api_name"))
  24.      } 
  25.  } 
  26.   
  27.  // get details of original invoice 
  28.  r_Invoice = zoho.crm.getRecordById("Invoices", p_InvoiceID)
  29.   
  30.  // start map 
  31.  m_Clone = Map()
  32.   
  33.  // loop through field names 
  34.  for each  v_FieldName in l_FieldApiNames 
  35.  { 
  36.      if(!isNull(r_Invoice.get(v_FieldName))) 
  37.      { 
  38.          m_Clone.put(v_FieldName,r_Invoice.get(v_FieldName))
  39.      } 
  40.  } 
  41.   
  42.  // now override fields specific to the newly cloned/duplicated record 
  43.  m_Clone.put("Invoice_Status","Repeated Invoice")
  44.  m_Clone.put("Invoice_Date",zoho.currentdate.toString("yyyy-MM-dd"))
  45.  m_Clone.put("Due_Date",zoho.currentdate.addMonth(1).toStartOfMonth().subDay(1).toString("yyyy-MM-dd"))
  46.   
  47.  // create the record 
  48.  r_Clone = zoho.crm.createRecord("Invoices",m_Clone)
  49.   
  50.  // get cloned invoice ID 
  51.  if(!isNull(r_Clone.get("id"))) 
  52.  { 
  53.      v_Duplicate_InvoiceID = r_Clone.get("id")
  54.  } 

Additional Note(s):
  • Invoice_Date in this example is the current date in format yyyy-MM-dd
  • Due_Date in this example is at the end of the current month: so add 1 month, go to the start of that month, subtract 1 day. .toEndOfMonth() used to work but appears to be deprecated.
  • Invoice_Ref_ID is excluded from being copied as it was an autonumber in our example.
  • zohoapis.eu is used in the above example for a client on the EU datacenters. If your datacenter is in the US then this should be zohoapis.com.

Additional Additional(s):
I haven't done any benchmark tests on this to compare but looking at different ways to exclude elements from a list:
copyraw
info l_FieldApiNames;
l_FieldApiNames = {"a","b","c","d","e"};

l_ExcludeFields = {"b","d"};
for each  v_FieldName in l_ExcludeFields
{
	l_FieldApiNames.removeElement(v_FieldName);
}
info l_FieldApiNames;

// yields: 
// a,b,c,d,e
// a,c,e

// compared to:
for each  v_FieldName in l_FieldApiNames
{
	if(!l_ExcludeFields.contains(v_FieldName))
	{
		... do stuff here ...
	}
}

// notes:
// no need to check if element exists on "removeElement"
  1.  info l_FieldApiNames; 
  2.  l_FieldApiNames = {"a","b","c","d","e"}
  3.   
  4.  l_ExcludeFields = {"b","d"}
  5.  for each  v_FieldName in l_ExcludeFields 
  6.  { 
  7.      l_FieldApiNames.removeElement(v_FieldName)
  8.  } 
  9.  info l_FieldApiNames; 
  10.   
  11.  // yields: 
  12.  // a,b,c,d,
  13.  // a,c,
  14.   
  15.  // compared to: 
  16.  for each  v_FieldName in l_FieldApiNames 
  17.  { 
  18.      if(!l_ExcludeFields.contains(v_FieldName)) 
  19.      { 
  20.          ... do stuff here ... 
  21.      } 
  22.  } 
  23.   
  24.  // notes: 
  25.  // no need to check if element exists on "removeElement" 

Zoho OAuth Connector
Just in case you don't know how to setup a Zoho OAuth Connector, here's how you do it in CRM:
  1. Login to Zoho CRM as an administrator and go to Setup
  2. Under Developer Space click on "Connections"
  3. Under Pick your Service click on "Zoho OAuth" (NOT "Zoho" - there are 2 Zoho options)
  4. Give the connection a name such as "myZohoConnector"
  5. Tick the applicable Scope(s): for example: "ZohoCRM.settings.fields.READ"
  6. Click on "Create" and then on "Accept" in the popup.
  7. You should be redirected to a page which lists the "status" as connected as well as a snippet of Deluge for the usage

Source(s):
Category: Zoho :: Article: 712

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.