Welcome back everyone!
Last week, we learnt how to Organize Contacts based on the Deal Stages. This week, let's look at a custom function that lets you transfer data captured from one module to the other along with the subform data.
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.
Getting started with the custom function:
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 a 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 code given above works only for V2 version of Zoho APIs. Please note that the code WILL NOT work for Version 1.0 APIs.
Found this useful? Try it out and let me know how it works! If you have questions, do not hesitate to ask! Share this with your team if you find it useful. Do check out other custom functions shared in this series here.
Writer is a powerful online word processor, designed for collaborative work.