Function-11: Turn a contact into a vendor.

Function-11: Turn a contact into a vendor.


Welcome back everyone! 

Last week, we learnt how toadd the international call prefix '+' and remove the alphbet from numeric fields. This week, let's look at a custom function that lets you turn a contact into a vendor with just the click of a button.

Business scenario:

The Vendors module in Zoho CRM facilitates efficient tracking of all vendor related details. It lets you create and associate vendor records with address, contacts, products, and such. We recommend this method for creating vendor records. However, what if you have a scenario where the vendor is already a part of your Leads/Contacts module via inbound communication? It is unproductive and redundant work to update Vendors module again for the records already updated.

Custom functions help you overcome this hurdle. It gives you the flexibility of replicating the details from the Leads/Contacts module to the Vendors module at the click of a button.

Getting started with the custom function:
  1. Go to Setup > Customization > Modules > Select the required module > Links and Buttons > +Create new button .
  2. Provide a name for the button. For example: “Create Vendor”. 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 “ contactId ” and select the value as “ Contact Id ”.
  10. Save the changes.
  11. 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!

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.