Quantcast
Channel: Zoho Creator Knowledge base » Form Actions
Viewing all 17 articles
Browse latest View live

Can I lock a record that is being edited, and restrict more than one user from editing the same record at the same time?

$
0
0

Yes, with Deluge Scripting you can lock a record that is being edited as described in the steps given below:

1. Create a Form, for example, with name “LockedID” with a number field to store the ID number of the record being edited in ‘Form X”.

2. In the on edit ->on load success of “Form X”, add script as shown in the format below.

The script checks if a record with the current ID exists in LockedID form. If exists, hide all the fields in the form and display the message that the record is in use, if not, the record ID will be added to the LockedID form.

Here, input.plain field refers to a “Add Notes” field type to display the required message.

Copy code
  1. if (count(LockedID[Number_Field == input.ID]) == 1)
  2. {
  3.    hide Email_ID;
  4.    hide Name;
  5.    input.plain = “This record is in use. Please try after sometime”;
  6. }
  7. else
  8. {
  9.    insert into LockedID
  10.    [
  11.        Added_User = zoho.loginuser
  12.        Number_Field = input.ID
  13.    ]
  14. }

3. In the on edit ->on success of “Form X”, add script as shown in the format below, to delete the record from LockedID form.

Copy code
  1. delete
    from LockedID[ Number_Field == input.ID ];

Note:

Please
note that the on edit ->on success script will be executed only when the record is updated on click on the
“Update” button. If the user, clicks on “Cancel” or “Close” button of the Edit dialog, the script will not be executed and hence the recordID which is locked will not be deleted.

A work around for the above
limitation is to run a custom schedule periodically on the LockedID form that will compare the Added_Time of the records with the current time and delete entries that are listed form than a specific period, say
5 to 10 min.


On Add ->On Load

$
0
0

On Add ->On Loadscript section in Deluge is used to execute your custom Deluge scripts when you add a record through a Zoho Creator Form. This part is executed immediately after the Form loads. 

  1. See https://creator.zoho.com/sampleapps/script-actions/#Form:On_Load . You will see an alert message as “Hello Zoho Creator User“.
  2. You can see the same message at https://creator.zoho.com/sampleapps/script-actions/#View:On_Load_View after clicking on the “Add” link. 
How to reach the On Add ->On Load section?
  1. Edit your application (by clicking on Edit this application link, or from the home page, click on the Edit link next to your application)
  2. Select your Form from the Forms tab. 
  3. Next to the Form name, click on More Actions ->Script (On Add) ->Actions on Load.
This will take you to the On Add ->On Load section of your Form’s script. You can drag and drop the deluge tasks from the left side to write your business logic there.

On Add ->On Validate

$
0
0

On Add ->On Validate section in Deluge is used to write the Form validation scripts. You can check for field values and tell the user to enter the right value. This part is executed after user clicks on the Submit button and before adding the record to the database. This script will also work when you import data, add records via email and duplicate the records.

For example, if you want to confirm a user’s email address using two fields Enter your Email and Confirm your Email and give an error if emails do not match, you can use the On Add ->On Validate script section.
  1. See https://creator.zoho.com/sampleapps/script-actions/#Form:On_Validate and give different email addresses for the fields you see there and click on Submit. 
  2. Access https://creator.zoho.com/sampleapps/script-actions/#View:On_Validate_View , click on Add and do the same. 
After you click on Submit (with different data for emails), you will see the message as “Invalid Entries Found” and “Email Addresses do not match“.
Note that this is different from the default Zoho Creator Form validation. If you did not enter the value in an email format, Zoho Creator will give “Invalid Entries Found” error. Because, they are both email fields and Zoho Creator will look for an email value in there.
How is the Message displayed?
  1. if statement is used to compare emails.
  2. alert task is used to display custom message.
  3. cancel submit task is used to cancel the Form submission in case of failures. 
How to reach the On Add ->On Validate section?
  1. Edit your application (by clicking on Edit this application link, or from the home page, click on the Edit link next to your application)
  2. Select your Form from the Forms tab. 
  3. Next to the Form name, click on More Actions ->Script (On Add) ->Validate on Form Submit.
This will take you to the On Add ->On Validate section of your Form’s script. You can drag and drop the deluge tasks from the left side to write your business logic there.

On Add ->On Success

$
0
0

On Add ->On Success section in Deluge is used to execute script actions after a record is added to the database. Sending an email, opening a new page are some examples.


In the sample Form at https://creator.zoho.com/sampleapps/script-actions/#Form:On_Success we have written an OpenUrl task to open the URL https://creator.zoho.com/support in a new window after you click on Submit. 

How to reach the On Add ->On Success section?
  1. Edit your application (by clicking on Edit this application link, or from the home page, click on the Edit link next to your application)
  2. Select your Form from the Forms tab. 
  3. Next to the Form name, click on More Actions ->Script (On Add) ->Actions on Success.
This will take you to the On Add ->On Success section of your Form’s script. You can drag and drop the deluge tasks from the left side to write your business logic there.

On Edit ->On Validate

$
0
0

On Edit ->On Validate section in Deluge is used to write the Form validation scripts when a record is edited. You can check for field values and tell the user to enter the right value. This part is executed after user clicks on the Update button and before updating the record to the database.

For example, while editing a record, if you want to confirm a user’s email address using two fields Enter your Email and Confirm your Email and give an error if emails do not match, you can use the On Edit ->On Validate script section.

See https://creator.zoho.com/sampleapps/script-actions/#View:On_Validate_View , click on Edit next to any record and give different email addresses for the fields you see there and click on Submit.


After you click on Submit (with different data for emails), you will see the message as “Invalid Entries Found” and “Email Addresses do not match“.

How to reach the On Edit ->On Validate section?
  1. Edit your application (by clicking on Edit this application link, or from the home page, click on the Edit link next to your application)
  2. Select your Form from the Forms tab. 
  3. Next to the Form name, click on More Actions ->Script (On Edit) ->Validate on Form Submit.

The same example was explained at https://kbase.creator.zoho.com/forms/on-add-on-validate

On Edit ->On Load

$
0
0

On Edit ->On Load script section in Deluge is executed immediately after the Edit Form loads.

See https://creator.zoho.com/sampleapps/script-actions/#View:On_Load_View and click on Edit next to any record. You will immediately see an alert message ”Hello Zoho Creator User“.
How to reach the On Edit ->On Load section?
  1. Edit your application (by clicking on Edit this application link, or from the home page, click on the Edit link next to your application)
  2. Select your Form from the Forms tab. 
  3. Next to the Form name, click on More Actions ->Script (On Edit) ->Actions on Load.
This will take you to the On Edit ->On Load section of your Form’s script. You can drag and drop the deluge tasks from the left side to write your business logic there.

On Edit ->On Success

$
0
0

On Edit ->On Success section in Deluge is used to execute script actions after a record is updated in the database. Sending an email, opening a new page are some examples.


If you edit any record at https://creator.zoho.com/sampleapps/script-actions/#View:On_Success_View and click on update, you will be taken to https://creator.zoho.com/support in a new window. We have written an OpenUrl task to open the URL https://creator.zoho.com/support in the On Edit ->On Success script section. See also https://kbase.creator.zoho.com/forms/on-add-on-success 

How to reach the On Edit ->On Success section?
  1. Edit your application (by clicking on Edit this application link, or from the home page, click on the Edit link next to your application)
  2. Select your Form from the Forms tab. 
  3. Next to the Form name, click on More Actions ->Script (On Edit) ->Actions on Success.
This will take you to the On Edit ->On Success section of your Form’s script. You can drag and drop the deluge tasks from the left side to write your business logic there.

On Delete ->On validate

$
0
0

On Delete ->On validate section validate before deleting any records from the database. 


If you try to delete any record from https://creator.zoho.com/sampleapps/script-actions/#View:On_Validate_View , you will get an error message as ”You do not have administrator privileges to delete records here”. 

Because that application checks for the logged in user and cancels the delete operation if he/she is not the administrator. Script below. 

  1. if ( zoho.loginuser != zoho.adminuser)
    {
  2. alert “You do not have administrator privileges to delete records here”;
  3. cancel delete;
    }

How to reach the On Delete ->On Validate section?
  1. Edit your application (by clicking on Edit this application link, or from the home page, click on the Edit link next to your application)
  2. Select your Form from the Forms tab. 
  3. Next to the Form name, click on More Actions ->Script (On Delete) ->Validate on Record Delete.
This will take you to the On Delete ->On Validate section of your Form’s script. You can drag and drop the deluge tasks from the left side to write your business logic there.


On Delete ->On Success

$
0
0

On Delete ->On Success, as the name suggests is executed after a record is successfully deleted. You can write your own script block in this part, like sending an email (openUrl is not supported here).


How to reach the On Delete ->On Success section?
  1. Edit your application (by clicking on Edit this application link, or from the home page, click on the Edit link next to your application)
  2. Select your Form from the Forms tab. 
  3. Next to the Form name, click on More Actions ->Script (On Delete) ->Actions on Success.
This will take you to the On Delete ->On Success section of your Form’s script. You can drag and drop the deluge tasks from the left side to write your business logic there.

Passing Parameters via URL

$
0
0

Passing parameters to Zoho Creator components via URL is possible. The below article explains how it is done for different components. 

  1. Form fields

    Form fields can accept parameters via URL. See this Form. The Form has a Name field and if you want to fill in the Name automatically via URL, the sample URL is here.

    If you want to pass values for multiple fields (like name and Email), you add an ampersand. Sample URL is here.

    Note that while passing field value as a parameter to the Form, the deluge name of the field should be used at the left side. There are two other URL methods used in Zoho Creator. 

    1. Form Perma -> Sample Url        

    2. Form Embed -> <iframe height=’500px’ width=’100%’ name=’zoho-Employee_Information’ frameborder=’0′ allowTransparency=’true’ scrolling=’auto’ src=’https://creator.zoho.com/sampleapps/employees/form-embed/Employee_Information/Name=Zoho Creator&Email=support@zohocreator.com‘></iframe>

  2. Data View Columns

    Like you passed the values to the Form field, you can also pass values to the View columns and filter the View. See this View. You can filter this View by any column. For example, you can pass the Name Value to it. Sample URL is https://creator.zoho.com/sampleapps/employees/#View:All_Employees?Name=Zoho

    You can also use other operators (like contains, not contains, not equal to, between). See this link for complete documentation.


    Other URL methods

    1. View Perma -> https://creator.zoho.com/sampleapps/employees/view-perma/All_Employees/Name=Zoho

    2. View Embed -> <iframe height=’500px’ width=’100%’ name=’zoho-All_Employees’ frameborder=’0′ scrolling=’auto’ allowTransparency =’true’ src=’https://creator.zoho.com/sampleapps/employees/view-embed/All_Employees/Name=Zoho‘></iframe>
     

  3. HTML View

    HTML Views can also accept URL parameters. See this page
    . Sample URL with parameter is https://creator.zoho.com/sampleapps/employees/#View:Complete_Employee_details?emp=support@zohocreator.com

    1. View Perma -> https://creator.zoho.com/sampleapps/employees/view-perma/Complete_Employee_details/emp=support@zohocreator.com

    2. View Embed -> <iframe height=’500px’ width=’100%’ name=’zoho-Complete_Employee_details’ frameborder=’0′ scrolling=’auto’ allowTransparency =’true’ src=’https://creator.zoho.com/sampleapps/employees/view-embed/Complete_Employee_details/emp=support@zohocreator.com‘></iframe>

    Read https://help.creator.zoho.com/Create-HTML-Views.html

How to convert Date format in Deluge Script

$
0
0

To convert the date format from “dd-MMM-yyyy” to “yyyy-MM-dd”, change the string with first format to date. Then convert that date object to a
string specifying the second format. The below is the sample function which converts the format of the date to “YYYY-MM-DD” and return it as a
string. Please refer to it.


  1. string changedateformat(string inputdate) //input date is string in format “DD-MMM-YYYY”. for eg. 10-Sep-2010.
  2. {
  3.    dt = input.inputdate.toDate(“dd-MMM-yyyy”);// converting input string to date object specifying its format.
  4.    dt1 = dt.toString(“yyyy-MM-dd”);  // Now we convert the date object to string
    with our required format.
  5.    return dt1;  // returning the string object.
  6. }
  • NOTE :
    The Date and Time pattern strings are mentioned below,
    • Date – dd
    • Month – MM (or) MMM (or) MMMM
    • Year – yy (or) yyyy
    • 12 hour format – hh
    • 24 hour format – HH
    • minute – mm
    • second – ss
    • AM/PM marker – a

I have configured an “on success”script with the “send mail”task with “From”address as “zoho.loginuserid”. But the send mail action fails to execute, why?

$
0
0

If your Form is accessed by users without logging in to Zoho Creator, the variable zoho.loginuserid will be set as “Public”. As “Public” is not an email address, the send mail action fails to execute. …

How can I check for duplication of records using Script?

$
0
0

The following sample code added to the Form actions ->on add ->on validate block and Form actions. ->on edit ->on validate block of the Script tab, will check if the same team member is added more than once to the Team Member form. If true, the submit action will cancel.

if (count(team_member[name == input.name]) >0)
{
alert "Name already exists";
cancel submit;
}

where,

team_member [name == input.name] – selects all the records from the team_member form whose name is equal to the name entered in this form.
input.name – it is the value for the field “name” given by the user while submitting the form
count – count operator returns the number of team members whose name is equal to the current name in the form (this.name)

How can I restrict the number of registrations to my form?

$
0
0

The following script added to the on add – validate block of the Script tab, checks if the number of records in the Registration form is equal to or greater than 20. Here, the count function is used to count the number of records in the Registration form. If the condition is satisfied, displays an alert message to the user and cancels the submission, so that the record is not stored in database.

 if(count(Employee[ID != 0]) >= 20)
{
alert("No more registrations allowed");
cancel submit;
}

Also refer the sample application Course Registration, which restricts the number of registrations to a specific course, based on the seats available.

How can I restrict entries to my Registration Form based on a given date?

$
0
0

Assume you have a Registration form to register for a specific course and the registration is open till 30th Dec 2009. To restrict entries from being submitted after this date, use the zoho.currentdate variable within the on add ->on validate block of the Script tab, to validate if the registration date has expired. The sample code is given below.

 if (zoho.currentdate >'20-Mar-2008')
{
alert "time for registration expired";
cancel submit;
}

Related Links


How can I restrict entries to my Form only from registered members?

$
0
0

The count function in Deluge Scripting enables you to count the number of records in a Form (table) that satisfies the given criteria. Using the count function, you can check if an entry already exists in a database. Let us illustrate this with the help of an example:

Assume, you have two forms: Members and Orders

- Members form contains the list of registered members with a valid MemberID, who are eligible to subscribe through Orders form .
- Orders form is used by registered members to submit their order. Hence, when a user submits data through Orders form, we need to validate to check if the user is already a registered member. This is achieved by writing Form Actions ->On Add ->On Validate script in Orders form , as given below:

if (count(Members[MemberID == input.MemberID])== 0)
{
alert " Specified MemberID is not Found in Members list";
cancel submit;
}

Code Explanation

1. The count built-in function will return the number of rows fetched from Form A, with the given criteria:

if (count(Members[MemberID == input.MemberID]) == 0)

2. The alert statement is executed if the count function returns 0

alert "Specified MemberID is not Found in Members list";

3. cancel submit statement will cancel the record update operation

cancel submit;

Can I restrict entries to my Form only from the admin user. If yes, how?

$
0
0

Yes, you can restrict entries only from the admin user. In the following code, Added_User stores the name of the user who added the current record and zoho.adminuser returns the name of the admin user. If the added user name is not equal to the admin user name, the record will not be added. The code is added on add ->validate block of the Script tab.

 if (input.Added_User != zoho.adminuser)
{
alert "You are not authorized to add records";
cancel submit;
}

Note:

Zoho Creator automatically tracks details about when and by whom a record was added or modified using the fields Added User, Added Time, Modified User and Modified Time. This information will be displayed in the view, if the columns are selected from Column Properties option of the View tab in Edit mode. Refer the topic, Display User name and time, for more information.

Viewing all 17 articles
Browse latest View live