Functions

Functions

Set Up Functions  

You can set up functions in six places:
  1. Create a standalone function.
  2. Associate function to a workflow rule.
  3. Use functions later by including them in Schedules.
  4. Set the function to get executed upon the click of a Custom Button.
  5. Associate a function to a Related List. 
To create a function
  1. Go to Setup > Developer Space > Functions.
  2. Select the My Functions page, click + New Function.
  3. In the Create Function page, do the following:
    1. Give a Name, Display Name and Description (optional) for the function.
    2. Choose the place (Category) where the function is meant to be added.



    3. Click Next.
    4. Click Edit Arguments.
    5. Set the arguments to be used in the script, with field name or custom value in Zoho FSM module.



    6. Write your required function in the Deluge Script Editor.



    7. Click Save & Execute to validate your code.
  4. Click Save.
The function will be listed in the List View of the My Functions page.
Please note that the functions specified to be used at a particular location cannot be used elsewhere. For example: a function configured for Workflow Rules cannot be used in Schedules.

Calling Functions using REST APIs  

A function lets you have additional functionalities and features in your Zoho FSM application apart from the conventional features. Functions needs a trigger to call it. The trigger could be in the form of a workflow, blueprint, related list or through the click of a button.

If the function needs to be triggered without employing these methods or from external sources, you can create standalone functions and make them available as API calls. Triggering functions through REST APIs which gives the flexibility to trigger it from anywhere inside Zoho FSM or from any third party application.

Sample function as an API call:  

A form which automatically generates a lead in Zoho FSM with the information given as input in a form.

Step 1: Create a standalone function with the following code.

newRecordInfo = Map();
newRecordInfo.put("Last_Name",LastName);
newRecordInfo.put("Company",Company);
newRecordInfo.put("Mobile",Mobile);
response = zoho.crm.createRecord("Leads",newRecordInfo);
id = response.get("id");
return id;



Note: The arguments to be passed for the above function are "LastName", "Company" and "Mobile". Datatype for the arguments is STRING.

Step 2: To make function available as an API
  1. Go to Setup > Developer Space > Functions.
  2. Hover over the name of the function and click the more options [] icon and select REST API.



  3. Set the API name for the custom function.
  4. Enable OAuth2.0 and the API key sliders.
  5. Click Save.

Note:
  1. Select OAuth2.0 for sharing the function as an API within your organization.
  2. Select API Key for the sharing the function with any 3rd party and enable it to be used by anyone.

Step 3:  
Using Zoho Creator, create a form such that it has the fields "LastName", "Company" and "Mobile". Program the function to get executed upon the click of Submit button.

Functions in Postman

Functions which are given as API calls can be tested using POSTMAN application. However, there are a few things that you need to keep in mind when executing a function in that app.
  1. The current supported methods for using a function as an API are GET and POST.
  2. In a POST request, under the "Body" section, select "form-data".
  3. Create a Key named "arguments" and the Value as the Input JSON object.
  4. The arguments can also be given in the URL as arguments={encoded_arguments}
  5. POST request - Arguments Limit
    1. In request URL - 5000 lines
    2. In body - 95000 lines (as JSON object)

Sample arguments in "Body":
{
"Last_Name":"Potter",
"Company":"Zylker",
"Mobile":"555-876-4367"
}

Deploying Functions in Workflow Rules  

To associate function to a workflow rule
  1. Go to Setup > Automation > Workflow Rules.
  2. In the Workflow Rules page, click + Create Rule.
  3. In the Create New Rule pop-up, specify workflow rule parameters.
  4. Under Instant Actions, select Function.



  5. Select the function you want to use and click Associate. Else click +New Function and write a script using Deluge script



  6. Click Save in the Workflow rule page.
Now, your customized function is associated with workflow rule. When the workflow rule is triggered, custom function will be automatically executed.

Points to remember
  1. You can associate up to 6 (1 Instant Action and 5 Time-Based Actions) functions per workflow rule.
  2. You can execute only 5000 lines (Statements) in a single function call.
  3. You can transfer data for a maximum of 10 fields from Zoho FSM to third-party applications using function.
  4. You can retrieve data from other Apps to Zoho FSM using function.
  5. You must update the API ticket regularly according to limits in third-party applications.
  6. You will not receive any email notification, if the function integration stopped functioning due to any issue in a third-party API.
  7. If there is any failure while connecting to Zoho Creator service, function will send the second notification after 15 min. Thereafter, the system will not send any notifications for that particular workflow trigger. Errors returned from Zoho Creator are shown under Reason for Failures section.
  8. If you exceed the maximum count per day, the system will not send remaining function notifications to third-party applications and will notify the failure to Administrator.
  9. Zoho FSM will the send the data in following standard format for Date and Date Time fields to third-party applications:
    1. Date: yyyy-MM-dd
    2. Date Time: yyyy-MM-dd hh:mm
  10. Limits for Custom Functions:
    1. Calls per Day - 10000 calls/day or 200 calls per user license for the org. (whichever is lower)
    2. Integration Tasks - 25000 Zoho API calls/day using deluge
    3. Get Data & Post Data - 25000 calls/day (totally)
    4. Send Email - 1000 emails/day

Refer Error Codes  

When the execution of function fails, one of the following error messages will be displayed in Zoho FSM:

HTTP Status Codes  

  1. 400 Bad Request: Often missing a required parameter.
  2. 401 Unauthorized: No valid API key provided.
  3. 402 Request Failed: Parameters were valid but request failed.
  4. 404 Not Found: The requested item doesn't exist.
  5. 500, 502, 503, 504 Server errors: Error in the third-party application.
  6. Error Code 1: Temporarily not able to connect to the API server. Check API server logs, firewalls settings for requests sent from Zoho FSM.

Custom Errors  

  1. Internal process failure: When the function is not executed due to errors in processing of the script.
  2. Day limit reached: When the company has reached the maximum limit for the day.
  3. Deluge Script: When the execution of workflow triggers fail due to errors in Deluge Script.

    • Related Articles

    • Functions

      Functions are the building blocks for developing an extension. They come handy for all server side customization. Sigma executes functions without additional infrastructure cost. External function calls can be done using rest APIs. You have to ...
    • Custom Functions

      Custom functions help in automation where procedural logic is required, which cannot be implemented with the default actions such as, Tasks, Webhooks, etc. With custom functions you can automatically update the data in the related Zoho Recruit ...
    • Custom Functions

      The Manage Business icon in the top menu bar is your go-to for managing all of your booking preferences. This page discusses Custom Functions. Aside from the default flow of a customer booking, you can define additional workflows at each stage of the ...
    • Custom Functions

      Super admins and admins can view and edit this information. Managers can only view this information. Staff members will not have access to this information. Custom functions help with automating actions that require procedural logic and that cannot ...
    • Custom functions

      Automate your issues workflow using Custom Functions. What Is a Custom Function? A custom function is a piece of code that can be used for automating a process. You can write your own function in Deluge and call it from one or more business rules. It ...