Custom functions

Custom Functions

On Zoho Flow, you can write your own Deluge code to create custom functions to make your workflows more powerful. These functions provide flexibility to achieve complex workflows that simplify repetitive tasks. For example, you can create a custom function that calculates the discount rate for your invoice, or a function to analyze your support tickets and alert you if there is a negative statement.

Custom functions can satisfy business-specific requirements by letting you write the entire function from scratch. Once created, they can be used by all members in your organization.

Create a custom function

Use an existing custom function

Delete a custom function

Deluge statements and tasks

Create a custom function

  1. Click the Logic tab on the left side of the builder.
  2. Click Custom Functions.
  3. Click +Custom Function.
  4. Enter a name. Remember that the name must start with a letter or underscore and can only include alphanumeric characters and underscores.
    E.g: _discount_calculation_1, autofill_zipcode
  5. Select a return type (output data type) and optionally specify the parameter (input) and its data type.
    Data TypeDescription
    voidNo value
    intInteger value
    floatDecimal value
    stringText
    boolEither true or false
    dateDate value
    mapKey-value mapping
    listList of values
    Note:
    • The return type will be void by default.
    • The input data type cannot be void.
  6. Click Create.
  7. Write the code for your custom function. Refer to Deluge documentation to learn more.
  8. Click Save.
  9. To modify the custom function code, click the edit icon on the function. Any member in the organization can edit or delete a custom function in the organization.

The created function will now be available under Custom Functions in the Logic tab.

Use an existing custom function

  1. Click the Logic tab on the left side of the builder.
  2. Click Custom Functions. You can view the list of existing custom functions in your organization.
  3. Drag and drop the function you want to use to the builder screen. A configuration window will open.
  4. Configure the function by entering the input parameter(s) of the function.
  5. Click Save.
  6. You can edit the custom function data you configure by clicking the edit icon on the right side of the custom function. You can also delete it like other actions.

Delete a custom function

  1. Click the Logic tab on the left side of the builder.
  2. Click Custom Functions. You can view the list of existing custom functions in your organization.
  3. On mouse over, the delete icon will appear. Click on it to delete the function.

If a custom function is deleted, all the flows using the function will be affected.

Deluge statements and tasks

These are blocks of code available on the left of the custom function coding screen. Drag and drop them onto the coding area and enter the required data.

Basic

Condition

Notifications

Integrations

Collection

Basic

Set Variable

Creates a variable with the given value that can be accessed within the action

For example: price = quantity*20

Every time the quantity value is changed, the value of the price will be modified

Add Comment

Adds comment to make your code understandable by others

For example: price = quantity*20 //Multiplies the quantity of the product order by 20 to calculate the total price

Any data that is after '//' will be considered a comment

Info

Prints the value of specified parameters as the function output in the history log

For example: info customer_names;

This prints the customer names in the history log

Condition

if

Checks for a condition. If the condition is true, it performs the specified action.

For example:

if (client_title == "CEO")

{

client_type = "premium";

}

This checks if the client title is CEO. If it is true, the client type is set to premium.

else if

Executes when the previous if statement is false and this statement is true

For example:

if (client_title == "CEO")

{

client_type = "premium";

}

else if (client_title == "Admin")

{

client_type = "standard";

}

When the client title is not CEO, but is Admin, the client type is set to standard

else

Executes when both if and else if statements fail

For example:

if (client_title == "CEO")

{

client_type = "premium";

}

else if (client_title == "Admin")

{

client_type = "standard";

}

else

{

client_type = "regular";

}

When neither if nor else if conditions hold true, the client type is set to regular.

Notifications

Send mail

Sends an email

[

from: frank@zylker.com

to: bruce@zylker.com

subject: Your request has been approved

message:

Hello Bruce,

Your request for a new laptop has been approved. Please contact your IT administrator to collect it.

Regards,

Frank Wilson

]

Integrations

webhook

Creates a webhook subscription for another application

param = Collection("TestParam":"TestValue");

header = Collection("Content-type":"application/json");

testWebhook = invokeurl

[

url :"https://requestb.in/1ckt5a31"

type: POST

parameters: param

headers: header

];

Learn more

Collection

create collection

Creates a map or a list depending on the input elements specified

For example: students = Collection ();

insert

Adds elements to the specified collection

For example: students.insert ("Kevin", "Jessica", "William", "Emma");

Adds the given names to the students list

For example: students. insert ("name":"Matt" , "grade":"8" , "subject":"English");

Adds the given key-value pairs to the map

get

Fetches a particular element from the specified collection

For example: students.get (6);

Fetches the value at index 6 from the students list

For example: students.get ("name");

Fetches the value mapped with the key 'name' in the students map

update

Updates the specified collection

For example: students.update(2,"Micheal");

Updates the value in the second element of the list to 'Micheal'

For example: students.update("grade":"9");

Updates the value in the key 'grade' to 9

for each element

Performs the task for each element in the specified collection

For example:

for each student_mail in students

{

myMessage = "Welcome to the students sports club. Please assemble at 9:00 am in the basketball court tomorrow.";

sendmail

[

from :zoho.loginuserid

to :student_mail

subject :"Invitation to Sports club"

message :myMessage

]

}

For every student email address available in the list, the mail will be sent

For example:

name = collection();

name.insert("First Name":"Emma", "Middle Name":"Marley", "Last Name":"Becker");

Fullname = "";

for each element in name

{

Fullname += (element+" ");

}

This function concatenates every value in the map. The output value of this function will be 'Emma Marley Becker'.

Note:

Date-time fields must be converted into string functions before being used in custom functions or data mapping.

Sample code:

This helps transform one date format into another and converts it into a string function.

string formatDate(string myDate, string fromFormat, string toFormat)

{

fromDate = myDate.toTime(fromFormat);

dateStr = fromDate.toString(toFormat);

return dateStr;

}

Create a custom function with the above code. Specify the following input parameters:

  • myDate - Date field from the previous step
  • fromFormat - Date format of the previous step
  • toFormat - Date format of the next step

For example, if you are creating this custom function between a MailChimp trigger and a Zoho Creator action, map myDate to the date field from MailChimp. fromFormat will be MailChimp's date format and toFormat will be Zoho Creator's date format.

Share this post : FacebookTwitter

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

Write to us: support@zohoflow.com