Function-23: Auto-update multiple fields of a record with same details.

Function-23: Auto-update multiple fields of a record with same details.



Welcome back people! Hope your new year is off to a great start!

Lets begin this year with a simple yet useful custom function that lets you automatically update multiple fields of a record with the same details.

Business Scenario:

Recently, we got an interesting request from one of our customers. She was looking to update multiple fields of a record with the same details. Though copy-paste was an obvious solution, she was convinced that automation would help cut down on errors resulting from manual work. Our team noted her requirements carefully and came up with tailor-made custom functions that delighted her.

Though the use-case appeared vague initially, at hindsight, we were convinced of its utility for customers at large. Here are two top-of-the-mind examples that we could think of:

  • Copying the amount value from 'Expected Revenue' field to the 'Amount' field in a Deals module.
  • Copying the information from the 'Phone' field to the 'Mobile' field in Leads module 
It's important to note that such options are available out-of-the-box for updating 'Billing Address' to 'Shipping Address' and vice versa. However, custom functions are required to extend this functionality to other fields.

Through this custom function, information from one field can be transferred to another field within a record, at the click of a button.

Getting started with the custom function:

Example 1 : Update the 'Amount' field value with information from 'Expected Revenue' field in Deals module.

  1. Go to Setup > Customization > Modules and Fields > Select the ' Deals ' module > Links and Buttons > +Create new button .
  2. Provide a name for the button. For example: “[The button's name]”. Add a description(optional).
  3. Choose View page from the drop-down list.
  4. Select Writing custom function from the subsequent drop-down.
  5. Provide a name for the custom function. Add a description(optional).
  6. Click “ Free flow scripting ”.
  7. Copy the code given below.
  8. Click “ Edit arguments ”.
  9. Enter the name as “ potId ” and select the value as “ Potential Id ”.
  10. Enter the name as “ value ” and select the value as “ Potential Expected Revenue ”.
  11. Save the changes.
Note:

  • In Zoho CRM, the Deals module was formerly referred to as Potentials.

The script:

Code for Version 2.0 API:
 
For amount :

mp=map(); 
mp.put("Amount",input.value); 
update=zoho.crm.update("Deals",input.potId.toLong(), mp); 
info mp; 
info update; 
return "Success"; 

For mobile:

mp = map(); 
mp.put("Mobile", input.phone); 
update = zoho.crm.update("Leads",input.leadId.toLong(), mp); 
info mp; 
info update; 
return "Success"; 

Code for Version 1.0 API:

potIdStr = input.potId.toString();
mp=map();
mp.put("Amount",input.value);
update=zoho.crm.updateRecord("Potentials", potIdStr, mp);
info mp;
info update;
return "Success";
------------------------------------------------------------------------------------------------------------------------

Example 2 : Update a "Mobile" field with information from "Phone" field in Leads module.

  1. Go to Setup > Customization > Modules and Fields > Select the ' Leads ' module > Links and Buttons > +Create new button .
  2. Provide a name for the button. For example: “[The button's name]”. Add a description(optional).
  3. Choose View page from the drop-down list.
  4. Select Writing custom function from the subsequent drop-down.
  5. Provide a name for the custom function. Add a description(optional).
  6. Click “ Free flow scripting ”.
  7. Copy the code given below.
  8. Click “ Edit arguments ”.
  9. Enter the name as “ leadId ” and select the value as “ Lead Id ”.
  10. Enter the name as “ phone ” and select the value as “ Lead phone ”.
  11. Save the changes.

The script:

Code for Version 2.0 API:
 
For mobile:
mp = map(); 
mp.put("Mobile", input.phone); 
update = zoho.crm.update("Leads",input.leadId.toLong(), mp); 
info mp; 
info update; 
return "Success"; 

Code for Version 1.0 API:

leadIdStr = input.leadId.toString();
mp = map();
mp.put("Mobile", input.phone);
update = zoho.crm.updateRecord("Leads", leadIdStr, mp);
info mp;
info update;
return "Success";
------------------------------------------------------------------------------------------------------------------------

Note:

  • The utility of this custom function is not limited to the above two use cases. To use the same custom function for updating other fields, replace the source and destination fields in the code accordingly.
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.

Update: As you must be aware, API V1.0 will be deprecated and support for version 1.0 API will be available only till Dec 31, 2018. Version 1.0 compatible Functions will continue to work until Dec 31, 2019. You're advised to migrated to API Version 2.0 at the earliest. Check this announcement for more. We've updated the post to include the Version 2.0 compatible Function.