Transfer record information from one module to another with subform datas

Business scenario:

The standard sales process involves entering the leads acquired through various channels to the CRM followed by lead qualification and conversion. The process is quite linear - create a lead --> qualify the lead --> convert it to contact --> create an account --> create a deal --> follow up with prospect --> win the deal. However, the sale process need not be linear on all occasions. What if your process involves copying CRM records from one module to the other seamlessly? Say for instance, you run a gaming company that follows freemium business model. The case involves 2 categories of users namely free and paid. . By default, the free customers are captured in the Leads module. Use the Function I'm sharing today to copy the records from the Leads module to the "Paid Customers" module once the user upgrades to the paid version. The best part is that the code copies not only the data from the standard and custom fields but also the data tracked using the sub-forms. Just need to ensure that the source and destination have the same subform fields and field types.

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.

As a result, if a Contact is associated with the deal, it is placed under the tag with the corresponding Deal Stage. Ex: if a deal associated with a Contact is in "Negotiation/Review" stage, the contact record is placed under the "Negotiation/Review" tag in the Contacts module. Include tags columns in the default/custom view of Contacts module to track the associated deal stage.

Getting started with the function:

  1. Go to Setup > Developer Space > Functions > + Create New Function.
  2. Select Automation as Function type and click Next.
  3. Provide a name for the function. Add a description(optional).
  4. Copy the code given below.
  5. Click Edit Arguments.
  6. Enter the name as leadId and select the type as Int.
  7. Click Save&Execute Script.
  8. Click Save.
 

The Code:


respMap = zoho.crm.getRecordById("Leads",leadId.toLong());
//info respMap;
mp = Map();
mp.put("Name",ifnull(respMap.get("Full_Name"),""));
mp.put("Division",ifnull(respMap.get("Division"),""));
mp.put("Project_Number",ifnull(respMap.get("Project_Number"),""));
mp.put("Customer_Name",ifnull(respMap.get("Account_Name"),""));
mp.put("Exchange_Rate",ifnull(respMap.get("Exchange_Rate"),""));
mp.put("Base_Currency",ifnull(respMap.get("Base_Currency"),""));
mp.put("Billing_Street",ifnull(respMap.get("Billing_Street"),""));
mp.put("Billing_State",ifnull(respMap.get("Billing_State"),""));
mp.put("Billing_Country",ifnull(respMap.get("Billing_Country"),""));
mp.put("Billing_Code",ifnull(respMap.get("Billing_Code"),""));
mp.put("Billing_CIty",ifnull(respMap.get("Billing_City"),""));
sub_forms = List();
subinfo = ifnull(respMap.get("Product_Details"),"");
//info subinfo;
for each rec in subinfo
{
subform = Map();
subform.put("Product",eachProd.get("product").get("id"));
subform.put("Quantity",rec.get("quantity"));
sub_forms.add(subform);
//info sub_forms;
}
mp.put("Product_Details",sub_forms);
create = zoho.crm.create("Paid_Users",mp,{"trigger":["workflow"]});
info create;
 

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's api' 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.
  • 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