Getting started with the custom function:
- Go to Setup > Customization > Modules > Select the required module > Links and Buttons > +Create new button .
- Provide a name for the button. For example: “Create Vendor”. Add a description(optional).
- Choose View page from the drop-down list.
- Select Writing custom function from the subsequent drop-down.
- Provide a name for the custom function. Add a description(optional).
- Click “ Free flow scripting ”.
- Copy the code given below.
- Click “ Edit arguments ”.
- Enter the name as “ contactId ” and select the value as “ Contact Id ”.
- Save the changes.
- Click Save to create the button.
The script:
This example code is for creating a record in Vendors module from Contacts module.
Code for Version 2.0 API:
contDetails = zoho.crm.getRecordById("Contacts", input.contactId.toLong());
fullname = ifnull(contDetails.get("Full_Name"),"");
name = "CLIENT : " + fullname;
mp = map();
mp.put("Vendor_Name", name);
mp.put("Phone", ifnull(contDetails.get("Mobile"),""));
mp.put("Email", ifnull(contDetails.get("Email"),""));
mp.put("Currency", ifnull(contDetails.get("Currency"),""));
mp.put("Street", ifnull(contDetails.get("Mailing_Street"),""));
mp.put("State", ifnull(contDetails.get("Mailing_State"),""));
mp.put("City", ifnull(contDetails.get("Mailing_City"),""));
mp.put("Zip_Code", ifnull(contDetails.get("Mailing_Zip"),""));
mp.put("Country", ifnull(contDetails.get("Mailing_Country"),""));
mp.put("Owner", "1234567890");
mp.put("Primary_Contact", ifnull(contDetails.get("id"),""));
create = zoho.crm.create("Vendors", mp);
info mp;
info create;
return "Vendor Created Successfully";
Code for Version 1.0 API:
contDetails = zoho.crm.getRecordById("Contacts", input.contactId.toLong());
first = ifnull(contDetails.get("First Name"),"");
last = ifnull(contDetails.get("Last Name"),"");
name = "CLIENT : " + first + " " + last;
mp = map();
mp.put("Vendor Name", name);
mp.put("Phone", ifnull(contDetails.get("Mobile"),""));
mp.put("Email", ifnull(contDetails.get("Email"),""));
mp.put("Currency", ifnull(contDetails.get("Currency"),""));
mp.put("Street", ifnull(contDetails.get("Mailing Street"),""));
mp.put("State", ifnull(contDetails.get("Mailing State"),""));
mp.put("City", ifnull(contDetails.get("Mailing City"),""));
mp.put("Zip Code", ifnull(contDetails.get("Mailing Zip"),""));
mp.put("Country", ifnull(contDetails.get("Mailing Country"),""));
mp.put("SMOWNERID", "1234567890");
mp.put("Primary Contact", ifnull(contDetails.get("CONTACTID"),""));
create = zoho.crm.create("Vendors", mp);
info mp;
info create;
return "Vendor Created Successfully";
Note:
- This custom function creates a record in a module with the information from another module, reducing duplicate work and improving efficiency.
- Change the name of the module from 'Contacts' to the intended module name and update 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 serieshere.
See you all next week with another interesting custom function. Ciao!