1. Select Workflow to invoke the Script builder.
2. Click on Functions tab displayed in the Script Editor. If no functions are defined, the dialog to create a new function will be displayed. If you have one or more functions already defined, the list of function names will be displayed on the left-side. Click on the New Function button displayed on the top left corner, to define a new function.
3. Specify the function name, namespace, return type and arguments, if any, to be passed to this function.
For example, let us create a simple function to calculate the number of days. Specify the function name as CalculateDays. This function takes arguments sdate and edate of type date, as inputs to this function, and the return type is int. Create the function by selecting the Create the Function button.
4. The function CalculateDays will be added to the Functions tree under the namespace Calculations, as shown in the screen-shot below. Select the function from the Functions tree and add the required deluge statements to be executed, using drag-n-drop or Free-flow scripting. Select Save Script to save the function.
5. You can use the Execute Script option to test if your function is executed as defined, by specifying the required values as arguments to the function. For example, to execute the Calculate days function, we specify a value for the arguments (sdate,edate). By clicking the On submit, the deluge statement is executed. The dialog box below shown below requests the user to enter a value for input arguments.
Select the Write Script option to define a function by directly writing or pasting the script code in the Functions dialog, as shown in the screen-shot below:
Zoho Creator supports Form Objects that can be passed as argument to a user-defined Function. A Form Object represents a collection of records in a Form. Refer the topic Passing Form object as argument to the function, for more information.
In the screen-shot given below, Calculations is the namespace that groups similar functions related to calculations. Here, CalculateDays, CalculateHours etc are function names. If the function is called within the application where it is defined, the namespace will be appended with the word thisapp. If the function is called from a different application, the namespace will be appended with the actual application name, where it is defined.
For example, if the function CalculateDays is called from the Sample application, the function call will be in the following format: Calculations.CalculateDays(),
- Calculations is the namespace,
- CalculateDays is the function name.