Data Access - Collection variable

Data Access - Collection variable

This guide will help you with the following:
  1. Overview
  2. Declaring a collection variable
  3. Aggregate functions
  4. Fetch field value from the first record
  5. Fetch values of a field from all the records in a collection
  6. Updating field value in a collection variable
  7. Applicable values for each field type

Overview

When you fetch a collection of one or more records, you get a collection variable.

Declaring a collection variable

  1. <collection_variable> = <form> [<criteria>];

Example

In the following example, the variable named employeesJoinedToday contains records of employees who have joined today. Joining_Date is the link name of a field in the Employees form.
  1. employeesJoinedToday = Employees [Joining_Date == zoho.currentdate];
Note:
  1. When the "sort" param is not specified, the fetched records are often sorted based on "added time" (oldest first) system field. However, there is no guarantee to this order and there is no guarantee that the order will remain constant over time. If you are particular about the sequence of the records, it is advisable to use the sort param.
  2. The Name and Address fields do not work with the sort by param.

Aggregate functions

You can use the following syntax to perform various functions:
  1. <collection_variable> = <form> [<criteria>].<method>;
(or)
  1. <collection_variable>.<method>;
Following are the methods that can be performed:
1. avg(<field_link_name>) ​
Returns: Average of all values of a specified field in a collection of records.
Applicable field types and the return type: Percent, Currency, Decimal, Formula(decimal) and Formula(bigint and decimal) field types will return Decimal data-type. Number and Formula(bigint) field types will return Bigint data-type.

2. count(<field_link_name>) ​
Returns: Count of records in a collection when the <field_link_name> is not specified. Else, it returns the number of values the specified field holds.
Return type: Bigint.
Applicable field types: Multi select, Checkbox, Drop-down and Radio fields will return the count of choices selected. All other field types will return the count of records in which the specified field is not null. 

3. distinct(<field_link_name>) ​
Returns: Distinct values a field holds in a collection of records.
Return type: List.
Applicable field types: All field types.

4. maximum(<field_link_name>) ​
Returns: Largest value of a specified field in a collection of records
Applicable field types and the return type: Percent, Currency, Decimal, Formula(decimal) field types will return Decimal data-type. Number and Formula(bigint) field types will return Bigint data-type. Date and Date-Time field types will return Timestamp data-type.

5. median(<field_link_name>) ​
Returns: Median value of a specified field in a collection of records sorted in ascending order.
Applicable field types and the return type: Percent, Currency, Decimal, Formula(decimal) field types will return Decimal data-type. Number and Formula(bigint) field types will return Bigint data-type.​

6. minimum(<field_link_name>) ​
Returns: Smallest value of a specified field in a collection of records.
Applicable field types and the return type: Percent, Currency, Decimal, Formula(decimal) field types will return Decimal data-type. Number and Formula(bigint) field types will return Bigint data-type. Date and Date-Time field types will return Timestamp data-type.

7. sum(<field_link_name>) ​
Returns: Total of all values of a specified field in a collection of records.
Applicable field types and the return type: Percent, Currency, Decimal, Formula(decimal) field types will return Decimal data-type. Number and Formula(bigint) field types will return Bigint data-type.

Fetch field value from the first record

To fetch a field value from the first record in a collection, use the following code:
  1. <variable> = <collection_variable>.<field_link_name>;
where,
<field_link_name>Link name of the field whose value has to be returned from the first record in the collection.
Example
The following syntax returns the employee id of the first record in collection variable employeesJoinedToday, and stores it the variable named empID. Employee_ID is the link name of a field.
  1. empID = employeesJoinedToday.Employee_ID;

Fetch values of a field from all the records in a collection

  1. <variable> = <collection_variable>.<field_link_name>.getAll();
where,
<field_link_name>Link name of the field whose values have to be returned from all the records in the collection.
Example
The following syntax returns the employee id field values from all the records in collection variable employeesJoinedToday, and stores it the variable named empID. Employee_ID is the link name of a field.
  1. empID = employeesJoinedToday.Employee_ID.getAll();

Iterating through records in a collection variable

To iterate through the records in a collection variable, use the following code:
  1. for each <record_variable> in <collection_variable>
  2.   {
  3.      fieldValue = <record_variable>.<field_link_name>;
  4.   }
where,

Example
The following code iterates through the records in collection variable employeesJoinedToday, and sends an email to each email address present in the collection. Email is the link name of the email field type.
  1. for each employee in employeesJoinedToday
  2.   {
  3.       sendmail
  4.          [
  5.            from: zoho.adminuser
  6.            to: employee.Email
  7.            subject: "Zylker : Offer Letter"
  8.            message: "Welcome to Zylker. Please find your offer letter attached with this email."
  9.          ]  
  10.    }

Updating field value in a collection variable

To update a field value in the first record in a collection, use the following syntax:
  1. <collection_variable>.<field link name> = <expression>;
where,

​​To update a field value in every record in a collection, use the below code:
  1. for each <record_variable> in <collection_variable>
  2. {
  3. <record_variable>.<field_link_name> = <expression>;
  4. }
where,

Example
The following syntax updates the Batch Sequence("number" field type) field with the value 118 for all the records in the collection variable employeesJoinedToday.
  1. for each emp in employeesJoinedToday
  2.   {
  3.     emp.Batch_Sequence = 118;
  4.   }

Applicable data type and expression for each field

1.
Field Type: Name
Data type: Text
Points Note:
  1. You must specify only the link name of the "Name" field when assigning it a value copied from another "Name" field.
  2. In all other cases, you have to give the values for its sub-fields separately as given below:
  3. <field>.prefix: denotes the "prefix" field.
  4. <field>.first_name: denotes the "first_name" field.
  5. <field>.last_name: denotes the "last_name" field.
  6. <field>.suffix: denotes the "suffix" field.
  7. You can add the above mentioned sub-fields even if they are not selected in the field's property.
Note:
If more than one Name fields are present in the form, the link names of the subsequent name sub fields will be appended by a number starting from 1. So, if we take the example of the subfield <field>.prefix, the link name of the first such field will be <field>.prefix, the link name of the second such field will be <field>.prefix1, the link name of the third such field will be <field>.prefix2, and so on.

2.
Field Type: Email
Data type: Text
Points Note
  1. The format of the specified email address must be valid. If the format of the specified email address is invalid, execution will be stopped during runtime.
  2. The number of characters in the value should not exceed the length specified in the "Character maximum" field property. If it exceeds, execution will be stopped during run-time.
3. 
Field Type: Address
Data type: Text
Points Note:
  1. You must specify only the link name of the "Address" field when assigning it a value copied from another "Address" field.
  2. In all other cases, you have to give values for its sub-fields separately as given below:
  3. <field>.address_line_1: denotes the "Address Line 1" field.
  4. <field>.address_line_2: denotes the "Address Line 2" field.
  5. <field>.district_city: denotes the "City / District" field.
  6. <field>.state_province: denotes the "State / Province" field.
  7. <field>.postal_Code: denotes the "Postal Code" field.
  8. <field>.country: denotes the "Country" field.
  9. <field>.longitude: denotes the "longitude" field.
  10. <field>.latitude: denotes the "latitude" field.
  11. You can add the above mentioned sub-fields even if they are not selected in the field's property.
Note:
If more than one address fields are present in the form, the link names of the subsequent address sub fields will be appended by a number starting from 1. So, if we take the example of the subfield <field>.country, the link name of the first such field will be <field>.country, the link name of the second such field will be <field>.country1, the link name of the third such field will be <field>.country2, and so on.

4.
Field Type: Phone
Data type: Text
Points Note:
  1. Value can be specified with or without the country code, even if the "Country code options" and "Default country code" field properties are not selected.
  2. Special characters like (), and - are supported to accept different phone number formats of various countries.

5.
Field Type: Single Line
Data type: Text
Points Note:
  1. The number of characters in the value should not exceed the length specified in the "Character maximum" field property. If it exceeds, execution will be stopped during run-time.

6.
Field Type: Multi Line
Data type: Text
Points Note
  1. The value can be plain text of maximum 64 kb size.

7. 
Field Type: Number
Data type: Number
Points Note
  1. If the number of digits specified in the value exceeds the length specified in the "Max Digits" field property, the extra digits will be trimmed from the right.

8.
Field Type: Date
Data type: Date-Time
Points Note
  1. All days in a week can be specified as value, irrespective of the selected days in "Allowed Days" property.
  2. Time value, if specified, will not get added.
9. 
Field Type: Time
Data type: Time
Points Note:
  1. Values ranging from 0 to 23 hours will be accepted for 24-hour format. Values ranging from 0 to 12 hours will be accepted for 12-hour format.
  2. Date value, if specified, will not get added. 

10. 
Field Type: Drop-down
Data type: Text
Points Note
  1. You can specify a new choice apart from pre-defined choices even if the "Allow Other Choice" field property is not selected.
  2. If a new choice is specified as the value, it only gets saved in the record and is not added as a new choice to be selected from the form UI. And that choice cannot be retrieved back if modified.

11. 
Field Type: Radio
Data type: Text
Points Note
  1. You can specify a new choice apart from existing choices even if the "Allow Other Choice" field property is not selected.
  2. If a new choice is specified as the value, it only gets saved in the record and is not added as a new choice to be selected from the form UI. And that choice cannot be retrieved back if modified.

12. 
Field Type: Multi Select
Data type: List
Points Note
  1. You can specify a new choice apart from the pre-defined choices.
  2. If a new choice is specified as the value, it only gets saved in the record and is not added as a new choice to be selected from the form UI. And that choice cannot be retrieved back if modified.

13. 
Field Type: Checkbox
Data type: List
Points Note
  1. You can specify a new choice apart from the pre-defined choices.
  2. If a new choice is specified as the value, it only gets saved in the record and is not added as a new choice to be selected from the form UI. And that choice cannot be retrieved back if modified.

14. 
Field Type: Decision box
Data type: Boolean
Points Note
  1. You can specify the value as True or False, with or without double quotes.
  2. If any other value is specified, execution will be stopped during run time.

15. 
Field Type: Rich Text
Data type: Text
Points Note:
  1.  There is no limit to the number or type of characters that can be specified as the value.

16. 
Field Type: URL
Data type: Text
Points Note
  1. Value can be specified in any of the the following formats:
    1. HTML text format: <a href= \"<URL>\" title = \"<TITLE>\" target = \"_blank\"><linkname></a> where: title, link name and target are optional params
    2. Plain text format: URL as such can be provided as a text enclosed with double quotes.
Note: Plain text format can be used only in the "On success", "On create", "On edit", and "On create or edit" workflow events.

17. 
Field Type: Image
Data type: Text
Points Note
  1. Value must be specified in the following format (title, linkname and target are optional params) :
  2. <a href= \"http://<LINKNAME>\" title =\"<TITLE>\" target = \"_blank\"><img src = \"<URL>\" title =\"<TITLE>\"></img></a>
  3. You must specify the image url as the value, even if the "Browse Options -Link" field property is not selected.
  4. The link must be that of a public image

18. 
Field Type: Percent
Data type: Decimal
Points Note
  1. If the number of digits specified in the value exceeds the length specified in the "Max Digits" field property, the extra digits will be trimmed from the right.
  2. If the specified decimal points exceed the number specified in "Decimal Points" field property, the extra decimal points will be trimmed from the right. 

19. 
Field Type: Currency
Data type: Decimal
Points Note
  1. If the number of digits specified in the value exceeds the value specified in the "Max Digits" field property, the extra digits will be trimmed from the right.
  2. If the specified decimal points exceed the number specified in "Decimal Points" field property, the extra decimal points will be trimmed from the right. 

20.
Field Type: Decimal
Data type: Decimal
Points Note
  1. If the number of digits specified in the value exceeds the value specified in the "Max Digits" field property, the extra digits will be trimmed from the right.
  2. If the specified decimal points exceed the number specified in "Decimal Points" field property, the extra decimal points will be trimmed from the right.

21.
Field Type: Date-Time
Data type: Date-Time
Points Note
  1. All days and hours can be specified as value, irrespective of the selected days and hours in "Allowed Days" and "Allowed Hours" property.
  2. If time value is not specified, 00:00:00 will be set as the time value.

22.
Field Type: Lookup(Display type - Dropdown/Radio Button)
Data type: Number
Points Note
  1. You must specify the record ID of the lookup form as the value.

23.
Field Type: Lookup(Display type - Multi Select/Checkbox)
Data type: List
Points Note
You must specify the record ID of the lookup form as the value.

24.
Field Type: File-upload
Data type: File-upload
Points Note
  1. Only a file value fetched from another File Upload field type should be specified as a value.

25.
Field Type: Audio
Data type: Audio
Points Note
  1. Only an audio file value fetched from another Audio field type should be specified as a value.

26.
Field Type: Video
Data type: Video
Points Note
  1. Only an video file value fetched from another Video field type should be specified as a value.

27.
Field Type: Users
Data type: Text
Points Note
  1. You can specify username of any user or developer added in your current app.
  2. You can view the list of users and developers in your account by navigating to Settings > Users. From this page, you can also add more users and developers to your account.
  3. If you enter an incorrect username, execution will be stopped during run-time.

28.
Field Type: Integration (Zoho CRM)
Data type: Text
Points Note
  1. You must specify the record ID in the selected module as the value. If you enter an incorrect ID, execution will be stopped during run-time.  

29.
Field Type: Integration (Zoho Recruit)
Data type: Text
Points Note
  1. You must specify the record ID in the selected module as the value. If you enter an incorrect ID, execution will be stopped during run-time.

30.
Field Type: Integration (Salesforce)
Data type: Text
Points Note
  1. You must specify the record ID in the selected module as the value. If you enter an incorrect ID, execution will be stopped during run-time.

31.
Field Type: Integration (Zoho Books)
Data type: Text
Points Note
  1. You must specify the record ID in the selected module as the value.
  2. If you enter an incorrect ID, execution will be stopped during run-time.

32. 
Field Type: Integration (Quickbooks)
Data type: Text
Points Note
  1. You must specify the record ID in the selected module as the value.
  2. If you enter an incorrect ID, execution will be stopped during run-time.


    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







                                                                                            You are currently viewing the help articles of Sprints 1.0. If you are a user of 2.0, please refer here.

                                                                                            You are currently viewing the help articles of Sprints 2.0. If you are a user of 1.0, please refer here.



                                                                                                  • Related Articles

                                                                                                  • Collection data type

                                                                                                    This guide will help you with the following: Overview Types Create a collection Insert data into a collection Retrieve data from a collection Iterate through a collection List/Map vs Collection Note: Collection data type is not to be confused with a ...
                                                                                                  • Collection Functions

                                                                                                    This guide will help you with the following: 1. Clear 2. containsKey 3. containsValue 4. delete 5. deleteAll 6. deleteKey 7. deleteKeys 8. distinct 9. duplicate 10. get 11. getAsString 12. getKey 13. getLastKey 14. insert 15. insertAll 16. intersect ...
                                                                                                  • Data Access - Update records

                                                                                                    This guide will help you with the following: Overview Syntax Applicable data-type and expression for each field Things to keep in mind Example Overview The update records deluge task updates(replaces) the value of a specified field with the given ...
                                                                                                  • Data Access - Maximum

                                                                                                    This guide will help you with the following: Overview Return Syntax Things to keep in mind Examples Overview The maximum function in the "aggregate records" deluge task returns the largest value of a specified field from records fetched based on ...
                                                                                                  • Data Access - Minimum

                                                                                                    This guide will help with you the following: Overview Return Syntax Things to keep in mind Example Overview The minimum function in the "aggregate records" deluge task returns the smallest value of a specified field from records fetched using a ...
                                                                                                    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