Extension Pointers: Learn to use Custom Variables while building extensions

Extension Pointers: Learn to use Custom Variables while building extensions

Looking for an option to store static information that can be accessed across an entire extension? The solution you're seeking is Custom Variables!

What are Custom Variables?

Custom variables store static information in your CRM. They are global variables that can be used in place of certain important fields in CRM to help users easily make personalized changes.

Consider a third-party integration scenario involving fields pertaining to personal data like a username, password, or authtoken. These values are user-specific and thus vary based on the user trying to access the application. So the developer will not be able to store or hard-code the value of these fields during the extension development process.

Custom Variables easily handle this situation by allowing the users to enter data from their end during the extension installation process. This data is then saved as the value for the field and provides a hassle-free experience.

Custom Variables for third-party integrations

Custom variables are of major importance in scenarios where data needs to be globally accessed across an entire extension, as well as during third-party integrations where security-related, user-specific data needs to be passed in order to establish a successful integration.

While most third-party applications today support the OAuth 2.0 authorization method for establishing an integration, there are few applications that support only API Key forms as an authorization method.

If the third-party application with which you wish to integrate supports API key forms, Custom Variables are the best option to establish an integration.

Note: To check out the integration process for applications using OAuth 2.0 authorization method, click here.

Methods involved while using custom variables

While using custom variables, there are situations where we might have to assign or pass the value of the custom variable across for performing logical functionalities or other tasks. In such cases we might need to either set or retrieve the value of custom variables accordingly. There are certain methods involved in manipulating the custom variable data—namely:
  1. Set Organization Variable
  2. Get Organization Variable
Set Organization Variable 

This is used to set the value of the custom variable.

Syntax:

<Response> = zoho.crm.invokeConnector("crm.set", <valueMap Map>);

where,
<Response> is the response details regarding the success or failure of updating.
<valueMap Map> is the map containing the key value pair denoting the API name of the custom variable to be updated, and the value with which the custom variable should be updated.

Get Organization Variable


This is used to fetch the value of the custom variable.

Syntax

<Response> = zoho.crm.getOrgVariable("<customVariableName>");

where,
<Response> returns the value of the custom variable.
<customVariableName> is the API name of the custom variable.

How to create a Custom Variable

1. Choose Custom Properties from the left panel of the Zoho Developer console under Build, and then click Create your first CRM variable.



2. Enter the necessary details and click Save. The value field is currently left empty for the users to later enter the value when prompted during the installation of the extension.



3. The custom variable is createdThe system also creates a unique API name for the custom variable in the following format "extensionNameSpace__VariableName"The system creates a unique API name by appending the extension name as a prefix. In our example, "API Key" is the custom variable created to hold the API key. "testcrm2__API_Keyis the unique API name provided by the system where "testcrm2" is the extension's unique namespace.



Similarly, let's create another custom variable to hold the user's email ID.



NoteYou can obtain the extension's NameSpace from the Extension Details page.





Establishing a connection with a third-party application (Datanyze)

The general flow involved around custom variables here is as follows:
  • While installing an extension, the user is prompted for values specific to authorization (set as custom variable in the extension) like username/password/API key.
  • The user enters the required value for the custom variable.
  • With the help of the data entered, the connection is established with the third-party application. 
For our example, let's take Datanyze as our third-party application. Datanyze mainly focuses on data enrichment through methodologies such as technographics and firmographics.

Note: The "API key" (also known as auth token) of Datanyze is required to complete the integration process. Log In or Sign Up with Datanyze to obtain a user-specific API key.

Let's write a custom function to see how the CRM tasks work and if the API call fetches us a response.



Code snippet:

valueMap = Map();


valueMap.put("apiname","testcrm2__API_Key");

valueMap.put("value","{API key token}");

resp = zoho.crm.invokeConnector("crm.set",valueMap);

info resp;

info "";

value = zoho.crm.getOrgVariable("testcrm2__API_Key");

info "The value of the custom variable, apikey, is " + value;

info "";

valueMap = Map();

valueMap.put("apiname","testcrm2__Email");

valueMap.put("value","{email id}");

resp = zoho.crm.invokeConnector("crm.set",valueMap);

info resp;

info "";

value2 = zoho.crm.getOrgVariable("testcrm2__Email");

info "The value of the custom variable, username, is " + value2;

info "";

response = invokeurl

[

url:"https://api.datanyze.com/industries/?

email={email}&token={API key token}"

type :GET

];

info response;

Here,

{email}
The Email ID associated with your Datanyze account.

{API key token} 
The API key generated by Datanyze for the corresponding {email}.

https://api.datanyze.com/industries/?email={email}&token={API key token}"
The Datanyze API call to get a list of all industries for data enrichment.


Click Execute to check the response.

The script returns
the status code as a response for the set organization variable method,
the value obtained as a response for the get variable method, and
a JSON response for the API call.

This indicates that locally the api key works fine and the response is fetched as expected.

When the extension is installed in a Zoho CRM account, the user is prompted for the API key and email.


Enter the API key and email. Click Save.

In our example, we've created two custom variables—testcrm2__Email and testcrm2__API_Key—for a user's Email ID and API key token, respectively, as required in the Datanyze API call to get a list of industries. Similarly, you can create any number of custom variables as needed.

You can also create and alter the function logic as needed to incorporate the data obtained from the Datanyze integration into your Zoho CRM.

We hope you found this content useful—keep following this space for more input!

SEE ALSO:









                            Zoho Desk Resources

                            • Desk Community Learning Series


                            • Digest


                            • Functions


                            • Meetups


                            • Kbase


                            • Resources


                            • Glossary


                            • Desk Marketplace


                            • MVP Corner


                            • Word of the Day



                                Zoho Marketing Automation


                                        Manage your brands on social media



                                              Zoho TeamInbox Resources

                                                Zoho DataPrep Resources



                                                  Zoho CRM Plus Resources

                                                    Zoho Books Resources


                                                      Zoho Subscriptions Resources

                                                        Zoho Projects Resources


                                                          Zoho Sprints Resources


                                                            Qntrl Resources


                                                              Zoho Creator Resources


                                                                Zoho WorkDrive Resources



                                                                  Zoho Campaigns Resources

                                                                    Zoho CRM Resources

                                                                    • CRM Community Learning Series

                                                                      CRM Community Learning Series


                                                                    • Tips

                                                                      Tips

                                                                    • Functions

                                                                      Functions

                                                                    • Meetups

                                                                      Meetups

                                                                    • Kbase

                                                                      Kbase

                                                                    • Resources

                                                                      Resources

                                                                    • Digest

                                                                      Digest

                                                                    • CRM Marketplace

                                                                      CRM Marketplace

                                                                    • MVP Corner

                                                                      MVP Corner

                                                                    





                                                                    




                                                                        Design. Discuss. Deliver.

                                                                        Create visually engaging stories with Zoho Show.

                                                                        Get Started Now