Why scripting in Zoho Creator ?

Posted by Posted on by
0

The first question that pops up whenever we demonstrate a cool new feature in Deluge is

Oops – Do I need to code ??

Most people want to create an entire application (even a complex one) interactively using the GUI. Doing it programatically is not the preferred option.

Zoho Creator does allow you build a data collection and viewing application like a Contact’s list without writing a single line of code. But if we are using Zoho creator for just creating trivial applications like these, then we are not utilizing its full potential. Users with such a requirement might even prefer to use an online spreadsheet like Zoho Sheet.

Zoho Creator is an application creator. You can create forms, configure default attributes for the fields and define relationship across forms interactively in the GUI mode. In addition, it also has a scripting language.

Though Zoho Creator could have had an interactive GUI (which will be done eventually), we have created a scripting language since

  • Complex data manipulations actually become simpler when you think programatically.
  • Deluge script is designed to be very easy and natural. It will be possible to understand the code even if a person looks at it for the first time.

To elaborate on it, let’s assume that a user wants to send a mail each time a form is submitted. It will definitely be very easy to do it if there are options to configure it in the GUI. And we do have plans for providing an interactive GUI for doing simple tasks like configuring a email. But if you wanted to create an application like a Library Manager (Read more about modifying data across forms – a usecase that involves rule evaluation and workflows), I am sure that it is not going to be very easy to understand it if it were presented graphically. Creating this application using an interactive GUI would have been tedious and even if it is done, the user interface is bound to be complex and later, it will be difficult to understand the logic involved in the created application.

Zoho Creator connects the graphical user interface with deluge scripting. The power of a usable GUI and a scripting language allows you to build powerful applications easily. It does have a slight learning curve but I think that it is worth the time spent.

Zoho Creator : Modify picklist items dynamically

Posted by Posted on by
0

There has been requests from users like Ted Hughes for automatically filtering picklists based on selection in the previous picklist. This can be done very easily now.

Let us take a Bug Tracker application as an example. This simple application has just three forms.

1. It has a form to fill in the modules. e.g. In the case of Zoho Creator, it could be user interface design, deluge script etc. See a list view of all the modules added.

2. It has a form to fill in the team member details. It has the name of the team member and the module he works for. See a list view of all the team members (and the respective modules).

3. It has a form for filing issues. Each of the issues filed has to be assigned to the appropriate team member. Since we have already defined the person in charge for each of the modules, it will make more sense if the items in the ‘Assigned to’ picklist gets updated every time the module is changed, listing only the relevant entries.

If ‘Persistence’ is selected in the ‘Module’ picklist, only those members of the team, in charge of the ‘Persistence’ module should get listed in the ‘Assigned to’ picklist. In this example, Edward and John should get listed.

This can be done by writing an ‘on change’ event for the ‘Module’ picklist.

Deluge code snippet:

must have Module
(
    type = picklist
    values = Add_Module.Module_Name
    on change
    {
        team = team_member [Module == input.Module];
        for each t in team
        {
            Assigned_to.add(t.name);
        }
    }
)


Explanation:

The code snippet given below fetches all the members of the team, in charge of the selected module.

team = team_member [Module == input.Module];

Since the variable team is an array, it has to be iterated to get the properties of each team member.

for each t in team
{
    Assigned_to.add(t.name);
}

The names of those team members in charge of the ‘Persistence’ module are added to the ‘Assigned to’ picklist.

Assigned_to.add(t.name);

I have taken a very simple use case to explain this feature. But I am sure our users will exploit its full potential and use it in a lot more interesting ways to enhance their applications.

Zoho Creator : Creating Ajax forms

Posted by Posted on by
2

We made another update in Zoho Creator and now you can

  • Improve the usability of a form by validating field data even before it is submitted.
  • Modify contents of the form dynamically when it is loaded.
  • Modify field values based on user action (on other fields).

See the sample registration form that you can even embed in your website. You can also see the working version and the deluge script.

1. It allows users to register till 1st January 2007. If you try to access the form after 1st Jan 2007, it will just display that the registration is closed. This validation is done when the form is loaded.

Deluge code snippet:

on load
{
    if (zoho.currenttime > ’01-Jan-2007 00:00:00′)
    {
         hide name;
         hide emailid;
         hide blog_url;
         hide about_yourself;
         hide emailiderror;
         set showmessage = “Registration is CLOSED!”;
    }
}

2. It is designed to accept only 100 registrations. It displays that the registration is closed if more number of people try to register. This validation is also done when the form is loaded.

Deluge code snippet:

on load
{
     if (count(Register) >= 100)
     {
         hide name;
         hide emailid;
         hide blog_url;
         hide about_yourself;
         hide emailiderror;
         set showmessage = “The registration is CLOSED!
We have exceeded the limit of 100 registrations”;
    }
}

3. A person can register with the same Email ID only once. This is done in the on change event of the Email ID field. An Ajax request is sent to the server to validate the Email ID.

Deluge code snippet:

on change
{
      if (count(Register[emailid == input.emailid]) > 0)
     {
           set emailiderror = “This email id already exists”;
           show emailiderror;
     }
}

We have added a few other features also in this update. Will be posting about them separately.
Do try this feature and send us your feedback / suggestions.

ZohoCreator : Custom formula

Posted by Posted on by
0

Creating custom formula is a powerful feature and it is a beginning to providing excel-like functions in Zoho Creator. Even the simplest of applications like a student marks database( given below as an example) or an expense tracker (to calculate the total expenses) requires custom fields that are calculated based on the values of other fields. They have to be created while defining the form and could be numeric, text, date or boolean.

* You can create calculated fields by selecting the field type as formula.

* All the types of form fields except multiple select fields can be used in formulas.
* The operators / functions that can be used in formulas can be found in the Deluge docs.
* The formulas will get recalculated when
  a. the formula is modified
  b. the values of the fields participating in the formula gets modified (when a record is updated).

Given below is a sample marks database application. The fields TotalMarks and AverageMarks are of type formula.


  application Student_marks_database
  {
     page Enter_marks
    {
      form Students_Mark_Sheet

      {
        Student_Name
        (
          type = text
        )
        English
        (
          type = number
          decimalplace = 2
        )
        Arts
        (
          type = number
          decimalplace = 2
        )
        TotalMarks
        (
          type = formula
          value = English + Arts
        )
         AverageMarks
        (
          type = formula
          value = (English + Arts) / 2
        )
      }
      list View_student_marks
      {
        Students_Mark_Sheet
      }
    }
  }

Please follow the following steps to create the sample application

* Login to Zoho Creator
* Click on Create Application
* Select Deluge script tab
* Copy & paste the code given below and save.

Your have now created a students marks database. You can now add some data and see the formula fields getting updated in the view.

Do send your comments / suggestions on this feature.

Zoho Creator : Form input validation

Posted by Posted on by
0

An application that gives a free ride to input incorrect data is useless. So validating form inputs is one area that needs to be done carefully while creating applications. Zoho Creator allows you to accurately validate the form inputs and helps you to give clear feedback to the user when the form does not accept the data.

Here is an overview that will help you to utilize this feature in Zoho Creator to the fullest.

Validations during a form submit can be classified as

  • User interface validation
    You can specify the constraints for the fields you are defining while creating a form. If you define a field to be of type Email, Zoho Creator checks if the data entered in the form for that field is a valid emailid, else it displays an error message to the user. Half the validation is done if you choose the type of the form field appropriately. By default, Zoho Creator supports an adequate number of field types.
  • Writing algorithmic logic
    In addition to performing user interface validation, you might want to check the user input with the data that you already have. Zoho creator allows you to write deluge script(an on submit action) for custom validation that will get executed before the form data is persisted.

What really happens when you submit a form in Zoho Creator ?

  • Zoho Creator first validates the submitted data based on the type of the field and properties defined for each of the fields.
  • The on submit action gets executed in the server. The default action of an on submit script is to submit the data, so you need to do a cancel submit if you want to stop a form from being submitted. You can also choose to provide proper error message to the user while canceling.
  • The same form is then shown to the user to re-enter the data.
  • Please note that the data gets persisted only if the on submit action does not get canceled.

Lets take a recruitment application for example to understand better. This sample recruitment application has just two forms

  • File Application
    Applicants can add fill in their details here. The admin can write deluge code to check if the application being posted satisfies the basic requirements, else he can display an error message and cancel the form submit. View the sample form and deluge code here.

The on submit action that executed while submitting the “Post Application” form is given below.

on submit
{
opening = New_Opening [Position_Name == $Applied_For];
if (opening.Status == “Closed”)
{
alert “The job profile ” + $Applied_For + ” for which you have applied is not currently open “;
cancel submit;
}
}

The code snippet given below fetches the data corresponding to the particular position applied by the applicant. You can access all the details related to that position by accessing the variable “opening”.

opening = New_Opening [Position_Name == $Applied_For];

The code snippet given below checks if the Status for that position is currently closed and displays an error message to the user.

if (opening.Status == “Closed”)
{
alert “The job profile ” + $Applied_For + ” for which you have applied is not currently open “;
cancel submit;
}

You can also read deluge help to learn more on scripting. Do try this feature and let us know your comments / suggestions.