Zoho Deluge: Duplicate/Clone a Record

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

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.

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:
Then check your URL is correct. The format for API v2 is:
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":
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
	for each  r_Field in r_Fields.get("fields")

// 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

// now override fields specific to the newly cloned/duplicated record
m_Clone.put("Invoice_Status","Repeated Invoice");

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

// get cloned invoice ID
	v_Duplicate_InvoiceID = r_Clone.get("id");

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:
info l_FieldApiNames;
l_FieldApiNames = {"a","b","c","d","e"};

l_ExcludeFields = {"b","d"};
for each  v_FieldName in l_ExcludeFields
info l_FieldApiNames;

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

// compared to:
for each  v_FieldName in l_FieldApiNames
		... do stuff here ...

// notes:
// 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


Related Articles

Joes Revolver Map


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:

Donate to Joel Lipman via PayPal

Donate to Joel Lipman with Bitcoin - Valid till 8 May 2022 3QnhmaBX7LQSRsC9hh6Je9rGQKEGNQNfPb
© 2021 Joel Lipman .com. All Rights Reserved.