Functions

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" : input.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();

l.add(updateDataMap);

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

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

respstr = updateResp+"";

}

return respstr;

}

REST API Functions

The REST API function provides you the flexibility of triggering it from anywhere - within a function in an extension or from a third-party application. Third-party applications can invoke these API functions as webhook URL. More details on REST API Functions can be found here.

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,

{"response":"{\"data\":[{\"code\":\"SUCCESS\",\"details\":
{\"Modified_Time\":\"2017-08-29T14:53:08+05:30\",\"Modified_By\":
{\"name\":\"Saranya \",\"id\":\"2641973000000124009\"},
\"Created_Time\":\"2017-08-29T14:28:16+05:30\",
\"id\":\"2641973000000128184\",\"Created_By\":{\"name\":\"Saranya \",
\"id\":\"2641973000000124009\"}},\"message\":\"record
updated\",\"status\":\"success\"}]}","status_code":200}

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 standalone function inside another standalone function is not supported.
  • Writing a function for Install Actions are also not supported.