Control Statements

Control Statements

Overview

A program consists of a number of statements which are usually executed in sequence.
Programs can be much more powerful if we can control the order in which statements are run. To achieve this, deluge script offers developers the
if,else if,else constructs.
  1. Conditional Execution - If, else if, else 
  2. Conditional IF statements 
  3. Conditional expressions in Formula field 

 Conditional Execution - If, else if, else

The 'If' construct in deluge is the same as that of other languages. It conditionally executes a set of statements depending on the value of the boolean expression.
Syntax
  1. if(<if-boolean-expression>)
  2. {
  3. <statements>
  4. }
  5. else if(<elseif-boolean-expression-1>)
  6. {
  7. <statements-1>
  8. }
  9. else if(<elseif-boolean-expression-2>)
  10. {
  11. <statements-2>
  12. }
  13. ..
  14. ..
  15. ..
  16. ..
  17. else if(<elseif-boolean-expression-n>)
  18. {
  19. <statements-n>
  20. }
  21. else
  22. {
  23. <statements>
  24. }
An If construct should adhere to the following rules:
  1. It should have an 'If' condition
  2. It can have zero or more 'else if' conditions
  3. It can have an optional 'else' part
When an <If Construct> is encountered during script execution, the condition specified by the <if-boolean_expression> is evaluated. If the condition is met, the statement in the <if statements> block are executed, but if the condition was not met, then the program flow skips the statements in the <if statements> block and searches for any else or else if keywords.

When an else if part is encountered, the condition specified by <boolean_expression-x> is evaluated and if the condition evaluates to true, the statements in <elseif statements-x> block is executed. If the <if condition> and all the <else if conditions> fails then the presence of <else> is searched and the statements in <else statements> block is executed.
 

Example - Free flow scripting

1. Let us first take an example of a simple if-condition. We have a form with fields Field_1 (Number Field Type),Field_2 (Number Field Type) and Field_3 (Decimal Field Type). If Field_1 and Field_2 are not null, Field_3 should evaluate ((Field_1*Field_2)/12). To achieve this, you can add the following code in the required Automate-> Workflow->Custom Function ->Create screen:
  1. if(input.Field_1 != null && input.Field_2 != null) 
  2. input.Field_3 == ((input.Field_1 * input.Field_2 ) / 12)) 
  3. }
2. Let us take the example. The deluge code added to the Automate-> Workflow->Custom Function ->Create block of the New_Applicant form is given below:
  1. opening = New_Opening [Position_Name == input.Applied_For];
  2. if (opening.Status == "Closed")
  3. {
  4. sendmail
  5. (
  6. To : input.Email_ID 
  7. From : zoho.adminuserid 
  8. Subject : "Reg application for job posted at recruitment.zoho.com" 
  9. Message : "The job profile " input.Applied_For " for which you have applied 
  10. is not currently open " 
  11. )
  12. }
  13. else if (opening.Experience == input.Experience)
  14. {
  15. sendmail
  16. (
  17. To : "manager-recruitment@adventnet.com" 
  18. From : zoho.adminuserid 
  19. Subject : "Applicants resume matches job profile" 
  20. Message : input.Applicant_Name " matches the job profile<br> Contact Info: "  
  21. input.Email_ID 
  22. )
  23. }
  24. else
  25. {
  26. sendmail
  27. (
  28. To : input.Email_ID 
  29. From : zoho.adminuserid 
  30. Subject : "Reg application for job posted at recruitment.zohoc
  31. )
Code Explanation:
  1. In the code, we first fetch the record from the New_Opening form, whose Position_Name matches with the position applied for.
  2. if status of the position is "Closed" the statements inside the if block is executed.
  3. if experience for the position is same as the experience specified, the statements inside the else if block is executed.
  4. if the above two conditions fail, the statements inside the else block is executed.

Conditional IF statements

If boolean-expression is TRUE, returns expression1; otherwise it returns expression2 .
  1. <variable> = IF( <boolean-expression>, <expression1>, <expression2>)
Example:
  1. str = IF( input.text=="test", "test-new", " ");
For NULL check, the simplified version of conditional IF is given below. If expression1 is not NULL , IFNULL() returns expression1 ; otherwise it returns expression2 .
  1. <variable> = IFNULL( <expression1>, <expression2>)
 

Conditional expressions in Formula field

Please refer this help topic  for more information on using conditional expressions in a Formula field.

    Zoho CRM Training Programs

    Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.

    Zoho CRM Training
      Redefine the way you work
      with Zoho Workplace

        Zoho DataPrep Personalized Demo

        If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.

        Zoho CRM Training

          Create, share, and deliver

          beautiful slides from anywhere.

          Get Started Now


            Zoho Sign now offers specialized one-on-one training for both administrators and developers.

            BOOK A SESSION








                                    You are currently viewing the help pages of Qntrl’s earlier version. Click here to view our latest version—Qntrl 3.0's help articles.




                                        Manage your brands on social media

                                          Zoho Desk Resources

                                          • Desk Community Learning Series


                                          • Digest


                                          • Functions


                                          • Meetups


                                          • Kbase


                                          • Resources


                                          • Glossary


                                          • Desk Marketplace


                                          • MVP Corner


                                          • Word of the Day


                                            Zoho Marketing Automation

                                              Zoho Sheet Resources

                                               

                                                  Zoho Forms Resources


                                                    Secure your business
                                                    communication with Zoho Mail


                                                    Mail on the move with
                                                    Zoho Mail mobile application

                                                      Stay on top of your schedule
                                                      at all times


                                                      Carry your calendar with you
                                                      Anytime, anywhere




                                                            Zoho Sign Resources

                                                              Sign, Paperless!

                                                              Sign and send business documents on the go!

                                                              Get Started Now




                                                                      Zoho TeamInbox Resources



                                                                              Zoho DataPrep Resources



                                                                                Zoho DataPrep Demo

                                                                                Get a personalized demo or POC

                                                                                REGISTER NOW


                                                                                  Design. Discuss. Deliver.

                                                                                  Create visually engaging stories with Zoho Show.

                                                                                  Get Started Now









                                                                                                      • Related Articles

                                                                                                      • Conditional Statements

                                                                                                        This guide will help you with the following: 1. Overview 2. Syntax 3. Examples Overview Conditional statements examine specified criteria, and act in one way if the criteria are met, or in another way if the criteria are not met. The criteria is ...
                                                                                                      • Criteria in conditional statements

                                                                                                        This guide will help you with the following: Overview Syntax Example Applicable operators and expressions for TEXT expressions Applicable operators and expressions for NUMBER and Decimal expressions Applicable operators and expressions for DATE-TIME ...
                                                                                                      • Assignment Statements

                                                                                                        Overview An assignment statement in Deluge uses the assignment operator (=) to assign the result of an expression to a variable. Syntax variable = expression;   Compound Assignment Operators A compound assignment operator is an operator that performs ...
                                                                                                      • Branching Statements

                                                                                                        Return Type: Return type is the data type specifier of the data returned by the function. If no data is returned by the function, the return type must be specified as void. Example 1: For AddRelatedList string getMySaasuData(string email) { ...
                                                                                                      • Debug Statements

                                                                                                        Description The info keyword is used in Validate, Success or Update actions to display debug messages to assist an app owner in debugging the application. The info message can be viewed only by the owner of the application by clicking on the ...
                                                                                                        Wherever you are is as good as
                                                                                                        your workplace

                                                                                                          Resources

                                                                                                          Videos

                                                                                                          Watch comprehensive videos on features and other important topics that will help you master Zoho CRM.



                                                                                                          eBooks

                                                                                                          Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho CRM.



                                                                                                          Webinars

                                                                                                          Sign up for our webinars and learn the Zoho CRM basics, from customization to sales force automation and more.



                                                                                                          CRM Tips

                                                                                                          Make the most of Zoho CRM with these useful tips.



                                                                                                            Zoho Show Resources