New built-in functions in Deluge

New built-in functions in Deluge

Hello everyone,

In today's post, let us begin with understanding functions, return values, arguments, and built-in functions. Towards the end of the post we will have a look at some of the newly supported built-in functions.

What are functions?
Functions do exactly what the name suggests. They are used to perform a specific 'function' or a task. Functions are used to combine multiple instructions to form a single piece of code meant to perform an action. And whenever you want to perform that action again, you do not have to write that code again. Instead you can simply 'call' or 'invoke' the function whenever required.
For example, a function can be written to find the average of three numbers. Once the function is created, it can be used as many times required, without having to rewrite the code all over again.

Arguments
The most important part in functions is arguments. Functions take in data in the form of arguments. For example, let's say you need a function that calculates the sum of two numbers. The two numbers could vary at different times. So in one place the numbers could be 10 and 5, in some other place it could be 20 and 25. Simply put, the function is meant to calculate the sum of two numbers which are going to be dynamic. To address this, we can specify two arguments to hold the numbers. Whenever the function is executed, the arguments are simply replaced with the numbers. The operation (in this example the operation 'sum') remains the same as defined in the script.

Argument is just programming jargon for input. Since functions aren't tied to any static or definite data, getting the outside data into your function's script requires arguments. Without arguments, Deluge wouldn't know which data your function should work with. 

Return values
Functions usually "take in" data, process it, and may or not "return" a result. The return is dependent on the script that you write within a function. For example, if you write a script to fetch a record from a specific service, then that function returns the value that has been fetched. If the script simply performs an action, for example if you write a script to add a record to a specific service and you do not want the status or response of the action in return, then that is a function without any return.

Note:
  • Configuring functions, arguments, and their return values depend on the Zoho service you are working on. 
  • We will come up with a central help page covering the working of custom functions in all Zoho services soon. Until then, you can refer to the product documents to learn about configuring custom functions.

Types of Function in Deluge 
In Deluge, functions can either be a user-defined function (custom function), where you decide what scripts are to be written in the function. Or, they could be built-in functions, where the scripts are written by us in the backend, and is readily available for you to use. 

Custom functions
For example, to calculate profit percentage you can create a custom function with the following code snippet. The inputs cost_price and selling_price of a product can be supplied to the function as arguments so the function will process them to calculate the profit percentage. Once the custom function is configured, you can use the same function to calculate profit percentages of different products by passing their cost and selling prices as arguments to this function.

  1. profit = selling_price - cost_price;
  2. percentage = (profit/cost_price)*100;

To trigger a custom function whenever an action is performed, associate it with an appropriate workflow. In Zoho Creator, you can also call the function within another function. 

Note: Configuring workflows to trigger custom functions depends on the Zoho service you are working on. 

Built-in functions
Another type of function that can be used in Deluge is built-in functions. It can be perceived as ready-to-use functions whose actions are pre-defined. That is, the script to perform the action, the required parameters, and the type of return value (if required) are already configured by us. This saves your time and effort as you can simply use them in your Deluge scripts by inputting arguments as expected by the function, without having to write the code.

For example, the leftPad built-in function inserts the specified number of white spaces to the beginning of the input text. This function expects you to supply two arguments specifying the input text and the number of white spaces to be inserted and it returns the padded text. The script required to pad the white spaces has already been written in the backend so you can directly use this function within your custom function. 

  1. lastName = leftpad("Watson",1);
  2. name = "John"+ lastName; // returns "John Watson"

In the above script, "Watson" and 1 are the arguments that are supplied to the leftpad functions and lastName is the variable that holds the return value - " Watson".

Deluge offers around 200 built-in functions so you can perform common actions, like computing the square root of a number, or checking if a given letter is present in a text. Each type of data has its set of built-in functions that allow you to manipulate it.You can refer to our help documents and flashcards to learn more. 

Let's now take a look at the built-in functions that we've recently supported. These functions are applicable for all Zoho services except Zoho Creator. We will eventually support them for Zoho Creator as well. 

Recent updates to built-in functions

Text functions: Functions that work on Text inputs
  • ltrim: Trims the leading white spaces from the given text
  • rtrim: Trims the trailing white spaces from the given text
Consider a concatenation function that will append two text values to return an ID. The following script uses the ltrim and rtrim functions to ensure no white spaces are inserted in between the texts.

  1. generated_ID = first_part.rtrim() + second_part.ltrim();

Here, first_part and second_part are the variables that hold the portions of the ID that need to be concentrated.
generated_ID is the variable that contains the concatenated text.

Number functions: Functions that work on Number and Decimal inputs
  • truncate: Limits the input decimal to the specified number of places to the left or right of the decimal point.
  • signum: Determines if the given number is negative, positive, or zero.
  • degrees: Converts the radians value into degrees
  • radians: Converts the degrees value into radians
  • sinhasinhcoshacoshtanh, and atanh: Perform the respective mathematical hyperbolic operations.
  • atan2: Finds the atan2 value of the specified point.
The following example converts the specified angle to radians and finds its hyperbolic sine value:

  1. angle_in_degrees = 90;
  2. angles_in_radians = angle_in_degrees.radians();
  3. sinh_value = angles_in_radians.sinh();

Here, the angle_in_degrees is the variable that holds the input angle in degrees.

We are working on offering around 70 more built-in functions in the near future. You can keep track of all the new releases, bug fixes, and improvements from our release notes. Do let us know your questions and suggestions in the comments.






      • Sticky Posts

      • Function #41: Sync Associated Subforms!

        Welcome back everyone! The last custom function showed how to update a Contact with Product details from it's Related list in Deals. This week, let's look at a function that lets you update subform records in two modules simultaneously when one of them is updated. Business scenario Let's look at how subform helps in an education institution that has deployed Zoho CRM. National Public School, Austin (made up, of course!) has set up Zoho CRM and it follows the same relationship pattern of "Students",