This guide will help you with the following:
1. Cancel Delete
2. App language identification
3. getFieldNames
4. getFieldValue
5. Set Variable
6. Set field value
7. Call function
8. return deluge task
9. Success message
10. Cancel submit
1. Cancel Delete
Overview
The "cancel delete" deluge task prevents data from being removed from the database when users try to delete records. An error message will be displayed to the user, which can be customized by using the alert task before "cancel delete".
This task is generally used in conditional statements, when a user must not be able to delete a record unless a specified condition is met.
Note: When the "cancel delete" task is triggered, all other deluge tasks except "send mail" task and API calls written in that "On Validate" section will be rolled back and won't get executed.
Syntax
This task can be used in the following events
Example
The following script disables the record deletion if the First Name field value is not specified
- if ( Name.first_name != "Null" )
- {
- cancel delete;
- }
2. App language identification
Overview
This task returns the language in which the application is accessed. For example, if English is the language configured for an application, the returned value is "English".
Note:
- This task is only applicable to Zoho Creator.
- The same app may be used by different users in different languages. This means the return value of this task may vary in different accounts depending on the language in which the app is accessed.
- This task can be executed in all workflow events.
Syntax
- <variable> = thisapp.localization.language();
Example
Let's say we have an application with language set to "User's browser language" in language settings. The app owner's browser language is English, and the shared user's browser language is French. The following snippet assigns the value "English" to 'language' field when executed in the app owner's account. When executed in the shared user's account, it assigns the value "French".
- language = thisapp.localization.language();
3. getFieldNames
Overview
The getFieldNames() function returns the link names of all the fields in a form.
Return Type
LIST
Syntax
- <variable> = getFieldNames();
- // this syntax is not applicable to custom functions
(OR)
- <variable> = <collectionVariable>.getFieldNames();
Example 1: Fetch field link name
The following snippet fetches records based on a given criteria and then extracts the field link names from a record in the collection.
- collectionVar = Registrations[Email == "john@zylker.com"];
- fieldNames = collectionVar.getFieldNames();
Example 2: Fetch display name of Zoho Creator fields using API
The following script fetches the display names of all the fields from the Zoho Creator form - form1 of the application - app1:
- appLinkName = "app1";
- formLinkName = "form1";
- authtoken = "54927XXXXXXXXXXXXXXXXXXXXXX924e3";
- url = "https://creator.zoho.com/api/json/" + appLinkName + "/"+ formLinkName + "/fields?authtoken=" + authtoken;
- response = invokeUrl
- [
- url: url
- type: GET
- ];
where:
response: The KEY-VALUE variable that holds the display name of all the fields of the specified form.
url: The TEXT that represents Zoho Creator API URL that lists all field names.
appLinkName: The TEXT variable that holds the link name of the application from which the field names need to be fetched.
formLinkName: The TEXT variable that holds the link name of the form whose fields need to be fetched.
authtoken: The TEXT that represents the authtoken of the Zoho Creator account from which the field names need to be fetched.
4. getFieldValue
Overview
The getFieldValue() function returns the value of a specified field.
Return Type
STRING
Syntax
- <variable> = getFieldValue(<fieldLinkName>);
- // this syntax will work in workflows except custom functions
(OR)
- <variable> = <collectionVariable>.getFieldValue(<fieldLinkName>);
Example
1) The following snippet fetches records based on a given criteria and then extracts the field values of the specified field and adds to a list variable.
- listVar=List();
- collectionVar=Registrations[Email=="john@zylker.com"];
- for eachrecincollectionVar
- {
- fieldName=rec.getFieldValue("PhoneNumber");
- listVar.add(fieldName);
- }
2) The following snippet iterates through all the fields fetched using getFieldNames() task, and stores the fields along with their values in the "values" variable.
- values = Map();
- for each field in getFieldNames()
- {
- values.put(field, getFieldValue(field));
- }
- info values;
5. Set Variable
Overview
The set variable deluge task can be used to create a local variable containing a given value.
Return
This task returns the stored value.
Syntax
- <variable> = <expression>;
Things to keep in mind
- Assigning a new value to a variable declared earlier will overwrite the existing value.
- Variables need not be declared initially before assigning values to them.
In Zoho Creator, this task can be used in the following events
Example
The following script assigns the value 0 to variable - temp:
6. Set field value
Overview
The set variable deluge task can be used to assign values to form fields.
Return Type
This task returns the stored value.
Syntax
- input.<field_link_name> = <expression>;
Things to keep in mind
- If a value is initially entered for a form in the UI, and a different value has been assigned to that field using this task in the On Validate or On Success event, the value assigned in the script will overwrite the value given in the UI when the form is submitted.
- If this task is used to assign a value to a field in the On Load event, the maximum characters property for that field is ignored. However, if you start editing the field, the maximum characters property will take effect.
- If "No Duplicate Values" is selected, and a duplicate value is specified in the "Add Record" task, the script execution will fail.
This task can be used in the following events
Example
The following script assigns the current date value to the field "Date".
- input.Date = zoho.currentdate;
7. Call function
Overview
The call function deluge task is used to invoke a custom function defined in any application in your account.
Return
Based on how the function is defined, it might or might not return a value.
The data-type of the returned value will be the data-type specified for the function while defining it.
Syntax
To invoke a function which returns a value, from current application
- <variable> = thisapp.<function_name>(<parameters>);
To invoke a function which does not return any value, from current application
- thisapp.<function_name>(<parameters>);
To invoke a function which returns a value, from different application in same account
- <variable> = <application_link_name>.<function_name>(<parameters>);
To invoke a function which does not return any value, from different application in same account
- <application_link_name>.<function_name>(<parameters>);
This task can be used in the following events
Example
1) Let's say we have defined a function in "Salary" application to calculate the average salary of a department:
- int getAvgSalary(String designation)
- {
- avgSalary=Employee[Designation = designation].avg(salary);
- return avgSalary
- }
We can invoke the defined function, for the "Sales" department, in the same app using the following snippet:
- Average_Sales_Salary = thisapp.getAvgSalary("Sales");
We can invoke the defined function, for the "Sales" department, in another application using the following snippet:
- Average_Sales_Salary = Salary.getAvgSalary("Sales");
8. Return Deluge Tasks
Overview
Functions are of two types - one which return a value, and the other which does not.
The return deluge task is used to specify the return value while using a function (which returns a value).
Note:
The return deluge task can be used only if a return type has been specified while creating the function.
Return
When the function is invoked, the value of the expression specified in the return statement will be returned.
Syntax
This task can be used in the following events
Example
The following function returns the number of days between two given dates
- int thisapp.CalculateDays(date sdate, date edate)
- {
- days = (((edate-sdate)/86400000)).toLong();
- return days;
- }
9. Success message
Overview
The success message deluge task is used to display a specified message after a form is successfully submitted.
The message specified in this task overrules the message specified through UI in form properties.
Syntax
- success message <expression>;
This task can be used in the following events
Example
The following snippet when triggered displays the specified success message.
- success message "Thanks for your feedback";
10. Cancel submit
Overview
The "cancel submit" deluge task prevents data from getting added to the database when users submit the form. An error message "Invalid entries found" will be displayed to the user, which can be customized by using the alert task before "cancel submit".
This task is generally used in conditional statements, when a user must not be able to submit a form unless a specified condition is met.
Note:
- When the "cancel submit" task is triggered, all other deluge tasks except "send mail" task and API calls written in that "On Validate" section will be rolled back and won't get executed.
- The "cancel submit" task also applies when data is being submitted through the Email Data feature or the Import data feature
Syntax
This task can be used in the following events
Example
The following script disables the form submission if the First Name field value is not specified
- if ( Name.first_name == "Null" )
- {
- cancel submit;
- }