How Can I...

Functions are the user-defined type of routines that performs a specific set of operations whenever called. They are defined in Zoho Developer as stand-alone functions written in Deluge Scripts and are module independent. So, these functions can be called inside any of the workflows to achieve the specified functionality.

Return Type and Arguments

  • Single or multiple arguments of supported data types can be passed as parameters to the functions.
  • Functions can return values with one of the supported data types.
  • The supported data types are Integer,Float,String,Boolean,Date,Map and List.

Types of Functions

Functions in Zoho Developer are categorised as Normal functions and REST API functions.

Create Functions

Normal Functions

These are the functions invoked in other workflow custom functions, custom buttons, Related lists and schedules.

To create a function,

  1. Log in to the Zoho Developer Console and click Extensions for Zoho CRM.
  2. Select the extension you want to create a function for, and click Edit.
  3. Click Automate in the left pane, then click Functions.
  4. Click Create Function in Functions page.
  5. In the Create Function page, fill in the following details,
    • Name of the function
    • Invoke as REST API - "No" for normal functions and "Yes" for REST API functions.
    • Select the return type of the function
    • Click Add Arguments if any,and specify the arg name and type
  6. Click Save.

A sample code snippet in Deluge Script for a normal function is given below,

string pluginname.Copy_Address(string module, int id)


m = { "module" : input.module, "id" : };

resp = zoho.crm.invokeConnector(("crm.get"), m);

response = (resp.get("response")).toMap();

data = response.get("data").toJSONList();

respstr = "";

for each rec in data


dataMap = rec.toMap();

idd = dataMap.get("id");

street = dataMap.get("Street");

city = dataMap.get("City");

state = dataMap.get("State");

country = dataMap.get("Country");

zip = dataMap.get("Zip_Code");

updateDataMap = map();

updateDataMap.put("installscript.Billing_Street", street);

updateDataMap.put("installscript.Billing_City", city);

updateDataMap.put("installscript.Billing_State", state);

updateDataMap.put("installscript.Billing_ZipCode", zip);

updateDataMap.put("installscript.Billing_Country", country);

updateDataMap.put("id", idd);

l = List();


updMap = { "module" : input.module, "data" : l };

updateResp = zoho.crm.invokeConnector("crm.update", updMap);

respstr = updateResp+"";


return respstr;


REST API Functions

Third-party applications can invoke these API functions as webhook URL with the "apikey" support (refer to this section). The API functions will return nothing. So their return type is void, but the parameter passed inside those functions will be of type Map and named as requestMap. The (Key, Value) pair of requestMap is given below,

ParametersThese are the map type entities found in requestMap as key-value pairs. For Example, in the URL,
, parameter is received as{"action":"mailreceived"} where "action" is the parameter name
and "mailreceived" is the parameter value. Then the map is got through the following code,
params = requestMap.get("parameters");
tp_event_responseIf the third party service sends data in InputStream, then the map is got through the code,
response = input.requestMap.get("tp_event_response")


Fetch the value of ZAPI key

The value of the ZAPI key can be obtained using one of the following:

  • Custom Functions
  • Installation scripts
Using Custom Functions
  1. Publish the extension in which the REST API Function is included and install the extension.
  2. Log in to your application.
  3. Go to Setup > Automation > Actions and select the Functions tab.
  4. Click the Configure Function button.
  5. Click the Write your own link.
  6. In the Deluge Script Editor, paste the following code snippet and click Save & Execute Script.

    m = {"nameSpace" : "<portal_name.extension_namespace>"};

    apikeyresp = zoho.crm.invokeConnector("crm.zapikey",m);

    zapikey = apikeyresp.get("response");

    info zapikey;

  7. The ZAPI key will be displayed in the Log messages.
Using Installation Scripts
  1. Log in to your Zoho Developer console and click Extensions for Zoho CRM.
  2. Select the extension in which the REST API Function is included, then click Edit.
  3. Select Custom Properties in the left pane.
  4. Click the Create button.
  5. Enter a variable name in  Field Name and API Name fields and click Save.
    This variable will be used in the installation script to store the URL of the REST API function (details are explained in the steps below).
  6. Select Install Actions in the left pane.
  7. Click Extension - On Installation.
  8. In the Deluge Script Editor, paste the below code snippet and click Save.

    m = { "nameSpace" : "<portal_name.extension_namespace>" };

    apikeyresp = zoho.crm.invokeConnector("crm.zapikey", m);

    zapikey = apikeyresp.get("response");

    url = "<extension_namespace.function_name>/execute?zapikey=" + zapikey;

    m = { "apiname" : "<extension_namespace.variable_name>", "value" : url };

    r = zoho.crm.invokeConnector("crm.set", m);

    info r;

  9. Publish the extension in which the REST API Function is included and install the extension.
  10. Log in to your application.
  11. Go to Setup > Marketplace > All > Installed and click the extension name.
    The value of the variable "apifunctionurl" will be displayed under the Extension Settings section of the Extension Details page. This variable will have the ZAPI key value.

The following function code snippet calls the third-party "Twilio" REST API as a webhook and associates it with the application,

resp = input.requestMap;

twilioResp = (resp.get("parameters")).toMap();

fromNumber = twilioResp.get("From");

messageContent = twilioResp.get("Body");

LeadRespList = zoho.crm.searchRecords("Leads", "("(Mobile|=|" + fromNumber + ")");

for each LeadRespinLeadRespList


LeadId = LeadResp.get("LEADID");

if ((LeadId == null) || (LeadId == ""))


LeadId = "";



ContactRespList = zoho.crm.searchRecords("Contacts", "(Mobile|=|" + fromNumber + ")");

for each ContactRespinContactRespList


FinalId = ContactResp.get("CONTACTID");

if ((FinalId == null) || (FinalId == ""))


FinalId = "";



updateMap = { ("twilioext.Incoming_Message_Content") : messageContent, "twilioext.SMS_Texts_Name" : ("Incoming SMS"), "twilioext.Lead" : LeadId, "twilioext.Contact" : FinalId, "twilioext.Direction" : "Inbound" };

m = map();

l = List();


m.put("module", "twilio.SMS_Texts");

m.put("data", l);

resp = zoho.crm.invokeConnector("crm.create", m);

signalleadResp = zoho.crm.getRecordById("Leads", LeadId.toLong());

Leademail = signalleadResp.get("Email");

if ((Leademail != "") || (Leademail != null))


signalMap = map();

signalMap.put("signal_namespace", ("twilioext.incomingsmssignal"));

signalMap.put("email", Leademail);

signalMap.put("subject", ("Incoming SMS"));

signalMap.put("message", messageContent);

actionsList = List();

actionMap = map();

actionMap.put("type", "link");

actionMap.put("display_name", "View Email");

actionMap.put("url", "");


signalMap.put("actions", actionsList);

result = zoho.crm.invokeConnector("raisesignal", signalMap);

info result;


signalcontactResp = zoho.crm.getRecordById("Contacts", FinalId.toLong());

Contactemail = signalcontactResp.get("Email");

if ((Contactemail != "") || (Contactemail != null))


signalMapx = map();

signalMapx.put("signal_namespace", ("twilioext.incomingsmssignal"));

signalMapx.put("email", Contactemail);

signalMapx.put("subject", ("Incoming SMS"));

signalMapx.put("message", messageContent);

actionsListx = List();

actionMapx = map();

actionMapx.put("type", "link");

actionMapx.put("display_name", "View Email");

actionMapx.put("url", "");


signalMapx.put("actions", actionsListx);

resultx = zoho.crm.invokeConnector("raisesignal", signalMapx);

info resultx;


Invoke Functions

Stand-alone functions are invoked inside custom functions,custom buttons,related lists and schedules as given below,

resp = <EXTENSIONNAME>.Copy_Address("Leads", <LEADID>);

The "Copy_Address" function generates output API response as,

{\"name\":\"Saranya \",\"id\":\"2641973000000124009\"},
\"id\":\"2641973000000128184\",\"Created_By\":{\"name\":\"Saranya \",

A Rest API function can be invoked similar to a normal function wherever it is necessary.

Edit Functions

To edit a function

  1. Log in to your Zoho Developer Console and select Extensions for Zoho CRM.
  2. Select the extension your function is associated with, and click Edit.
  3. Click Automate option in the left pane, then click Functions.
  4. Select the required function from the list and click the Edit icon [].
  5. Edit and update the changes as per your requirements.

Delete Functions

To delete a function

  1. Log in to your Zoho Developer Console account and select Extensions for Zoho CRM.
  2. Select the extension associated with the function you wish to delete, and click Delete.
  3. Click Automate option in the left pane and click Functions.
  4. Choose the function that you want to delete, and click the Delete icon [].
  •  Calling a function inside another function is not supported.
  • Writing a function for Install Actions are also not supported.

Share this post : FacebookTwitter

Still can't find what you're looking for?

Write to us: