Transfer record information from one module to another, based on specific criteria

Business scenario:

Custom Modules enable you to create entire modules according to your requirements. You can also define the layout of the record in the module, set up layout rules, customize the fields of a record, set up hyperlinks and buttons, etc. This helps reduce clutter and organize your business information efficiently.

The custom function for today is quite similar to Lead Conversion. The difference is that it performs the conversion task on any modules. For instance, let's say you run a gaming company and have 2 custom modules, named Free Customers and Paid Customers. Set the custom function to automatically transfer the lead information to a record in the Free Customers module after making contact with the lead.

Create a Picklist named "Paid" with options "Yes" and "No". Tie the custom function I'm sharing today to this Picklist - I"ll tell you how to do it - such that the custom function gets invoked if "Yes" is picked. Set the default value to be "No" and leave the record as is if the customer prefers using the free plan. However, if the customer agrees to upgrade to paid plan, update the Picklist as "Yes". This invokes the custom function and moves the record to the Paid Customers module.This takes your business process automation taken to a whole new level.

Include this custom function in a Workflow Rule by setting the condition as "This workflow will be executed whenever the field Paid is updated." Alternatively, set a Custom Button to execute this custom function upon click.

 

Getting started with the function:

Step 1: From Leads to a Custom Module

  1. Go to Setup > Automation > Actions > Functions > Configure Function > Write your own.
  2. Provide a name for the function. For example: “Business Automation - 1”. Add a description(optional).
  3. Choose the module as Deals.
  4. Copy the code given below.
  5. Click Edit Arguments.
  6. Enter the name as leadId and select the value as Lead Id.
  7. Save the changes.
 

The Code:


leadIdLong = input.leadId.toLong();
leadDetails = zoho.crm.getRecordById("Leads",leadIdLong);
mp = map();
mp.put("Name",ifnull(leadDetails.get("Full_Name"),""));
mp.put("Annual_Revenue", ifnull(leadDetails.get("Annual_Revenue"),""));
mp.put("Billing_City", ifnull(leadDetails.get("City"),""));
mp.put("Billing_Country", ifnull(leadDetails.get("Country"),""));
mp.put("Description", ifnull(leadDetails.get("Description"),""));
mp.put("Fax", ifnull(leadDetails.get("Fax"),""));
mp.put("Industry", ifnull(leadDetails.get("Industry"),""));
mp.put("Employees", ifnull(leadDetails.get("No_of_Employees"),""));
mp.put("Phone", ifnull(leadDetails.get("Phone"),""));
mp.put("Rating", ifnull(leadDetails.get("Rating"),""));
mp.put("Billing_State", ifnull(leadDetails.get("State"),""));
mp.put("Billing_Street", ifnull(leadDetails.get("Street"),""));
mp.put("Billing_Code", ifnull(leadDetails.get("Zip_Code"),""));
mp.put("Website", ifnull(leadDetails.get("Website"),""));
create = zoho.crm.create("CustomModule1apiname", mp);
info mp;
info create;
 

Note:

  • Replace 'CustomModule1apiname' with the custommodule's api name.
 

Step 2: From one Custom Module to another

  1. Go to Setup > Automation > Actions > Functions > Configure Function > Write your own.
  2. Provide a name for the function. For example: “Business Automation - 2”. Add a description(optional).
  3. Choose the module as Deals.
  4. Copy the code given below.
  5. Click Edit Arguments.
  6. Enter the name as CustommoduleId and select the value as Custom Module Id.
  7. Save the changes.
 

The Code:


CustommoduleDetails = zoho.crm.getRecordById("CustomModule1apiname", input.CustommoduleId.toLong());
createMap = map();
createMap.put("Name", ifnull(CustommoduleDetails.get("Name"),""));
createMap.put("Owner", ifnull(CustommoduleDetails.get("Owner"),"").get("id"));
createMap.put("Phone", ifnull(CustommoduleDetails.get("Phone"),""));
createMap.put("Email", ifnull(CustommoduleDetails.get("Email"),""));
createCustomModule = zoho.crm.create("CustomModule2apiname", createMap);
info createMap;
info createCustomModule;
 

Note:

  • Replace 'CustomModule1apiname' with the custommodule1's api name.
  • Replace 'CustomModule2apiname' with the custommodule2's api name.
 

Adding to the workflow

  1. Go to Setup > Automation > Workflow Rules.
  2. Click '+ Create Rule'.
  3. Select the Module for which this custom function has to be added and give it a name and a description(optional).
  4. Select "On a record action" in the "When do you want to execute this rule?".
  5. Select "Field Update" and click Next.
  6. Select the Condition as "Paid".
  7. Select the checkbox "Repeat this workflow whenever a record is edited." and Click Next.
  8. Choose "Function" from Instant Actions.
  9. Select the option "Function (Created by users from your organization)".
  10. Select the required custom function and click Configure.
  11. Click Save and Associate.
  12. Save the workflow.
 

Note:

  • Use the code to transfer information between any two modules. Update the module names in the code accordingly.
  • Similar to "ID" of a record, the "ID" for a Custom Module is "CustomModule1", "CustomModule2", etc, in the order of creation. For instance, if Free Customers is created first and Paid Customers is second. Then ID of Free and Paid Customers is CustomModule1 and CustomModule2 respectively.
  • Create a Custom Field in the 1st module named "Date Created", or any name for that matter. It helps you to keep track of when you made contact with the customer, rather than the date in which the record in the 2nd module was created, which leads to discrepancies. Since the 2 modules are the same, creating this custom field lets you to know when the customer was contacted and when he turned into a "Paid Customer".
  • The above code works only for API V2.0 and not the previous version.
 

Found this useful? Try it out and let us know how it works! If you have questions, do not hesitate to ask! Share this with your team if you find it useful!

Return to Tips