Welcome back everyone!
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 custom function:
Step 1: From Leads to a Custom Module
- Go to Setup > Automations > Actions > Custom Functions > Configure Custom Function > Write your own.
- Provide a name for the custom function. For example: “Business Automation - 1”. Add a description(optional).
- Select the module as Deal. Add a description (optional).
- Click “Free flow scripting”.
- Copy the code given below.
- Click “Edit arguments”.
- Enter the name as “leadId” and select the value as “Lead Id”.
- Save the changes.
The script:
Code for Version 2.0 API:
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.
Code for Version 1.0 API:
leadIdLong = input.leadId.toLong();
leadDetails = zoho.crm.getRecordById("Leads", leadIdLong);
name = ifnull(leadDetails.get("First Name"),"") + " " + ifnull(leadDetails.get("Last Name"),"") ;
mp = map();
mp.put(("CustomModule1 Name"),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(("CustomModule1"), mp);
info mp;
info create;
Step 2: From one Custom Module to another
- Go to Setup > Automations > Actions > Custom Functions > Configure Custom Function > Write your own.
- Provide a name for the custom function. For example: “Business Automation - 2”. Add a description(optional).
- Select the Custom Module as the module. Add a description (optional).
- Click “Free flow scripting”.
- Copy the code given below.
- Click “Edit arguments”.
- Enter the name as “CustommoduleId” and select the value as “CustomModule Id”.
- Save the changes.
The script:
Code for Version 2.0 API:
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.
Code for Version 1.0 API:
CustommoduleDetails = zoho.crm.getRecordById("CustomModule1", input.CustommoduleId);
createMap = map();
createMap.put("CustomModule2 Name", ifnull(CustommoduleDetails.get("CustomModule1 Name"),""));
createMap.put("SMOWNERID", ifnull(CustommoduleDetails.get("SMOWNERID"),""));
createMap.put("Phone", ifnull(CustommoduleDetails.get("Phone"),""));
createMap.put("Email", ifnull(CustommoduleDetails.get("Email"),""));
createCustomModule = zoho.crm.create("CustomModule2", createMap);
info createMap;
info createCustomModule;
Adding to a workflow:
- Go to Setup > Automation > Workflow Rules.
- Click '+ Create Rule'.
- Select the Module for which this custom function has to be added and give it a name and a description(optional).
- Select "On a record action".
- Select "Field Update" and click on Next.
- Select the Condition as "Paid".
- Select the checkbox "Repeat this workflow whenever a record is edited." and Click Next.
- Choose "Custom Function" from Instant Actions.
- Select the option "Custom Function" (Created by users from your organization).
- Select the custom function you just added and click on Configure.
- Click on "Save and Associate".
- 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".
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.
See you all next week with another interesting custom function. Ciao!