Collection Functions

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
17. isEmpty
18. keys
19. percentile
20. size
21. sort
22. sortKey
23. toCollection
24. update
25. values
26. notContains

Clear

The clear function empties a given collection.

Syntax

  1. <collectionVariable>.clear();
where,

Examples

  1.  productVersion=collection("Deluge":5,"CRM":2,"Mail":8);
  2.  productVersion.clear();
  3.  info productVersion;// Returns {}

containsKey

The containsKey function checks if a specified key or an index value is present in a collection. It returns true if the key or the index is present in the collection. Otherwise, it returns false.
Note: This function performs a case sensitive search.

Return Type

BOOLEAN

Syntax

To check if a key is present in a collection:
  1. <variable>=<collectionVariable>.containsKey(<key>);
(OR)
To check if an index value is present in a collection:
  1. <variable>=<collectionVariable>.containsKey(<index>);
where,

Examples

  1.  productVersion=collection("Creator":5,"CRM":2,"Mail":8);
  2.  info productVersion.containsKey("CRM"); // Returns true
  3.  productVersion=collection("Creator","CRM","Mail");
  4.  info productVersion.containsKey(3); // Returns false

containsValue

The containsValue function checks if a specified value is present in a collection. It returns true if the value is present in the collection. Otherwise, it returns false.
Note: This function performs a case sensitive search.

Return Type

BOOLEAN

Syntax

  1. <variable>=<collectionVariable>.containsValue(<value>);

Examples

  1. productVersion=collection("Creator":5,"CRM":2,"Mail":8);
  2. info productVersion.containsValue(2);// Returns true

delete

The delete function deletes a specified element, or a specified value (along with the key) from a collection.

Syntax

To delete a value along with the key:
  1. <collectionVariable>.delete(<value>);
(OR)
To delete an element:
  1. <collectionVariable>.delete(<element>);
where,

Examples

  1.  products=Collection("Creator","CRM","Campaigns");   
  2.  products.delete("CRM"); 
  3.  info products;// Returns "Creator,Campaigns"
  4.  productVersion=Collection("Creator":5,"CRM":2);
  5.  productVersion.delete(2); 
  6.  info productVersion;// Returns {"Creator":5}

deleteAll

The deleteAll function deletes specified elements, or specified values (along with the keys) from a collection.

Syntax

To delete values along with the keys:
  1. <collectionVariable>.deleteAll(<valuesList>);
(OR)
To delete elements:
  1. <collectionVariable>.deleteAll(<elementsList>);
where,

Examples

  1.  products=collection("Creator","CRM","Campaigns");   
  2.  products.deleteAll({"CRM","Campaigns"});// deletes the specified elements from the collection
  3.  productVersion=collection("Creator":5,"CRM":2);   
  4.  productVersion.deleteAll({2});// deletes the specified key along with its value from the collection

deleteKey

The deleteKey function deletes an element based on a specified index, or a specified key along with its value in a collection.

Syntax

To delete a key-value pair based on the key:
  1. <collectionVariable>.deleteKey(<key>);
(OR)
To delete an element based on its index:
  1. <collectionVariable>.deleteKey( <elementIndex> );
where,

Examples

  1.  productVersion=collection("Creator":5,"CRM":2);
  2.  productVersion.deleteKey("CRM");// deletes the specified key along with its value
  3.  products=collection("Creator","CRM","Campaigns");
  4.  products.deleteKey(1);// deletes the element "CRM"

deleteKeys

The deleteKeys function deletes specified elements, or keys(along with their values) from a collection.

Syntax

To delete keys along with their values:
  1. <collectionVariable>.deleteKeys(<keysList>);
(OR)
To delete elements based on index values:
  1. <collectionVariable>.deleteKeys(<indexList>);
where,

Examples

  1.  productVersion=collection("Creator":5,"CRM":2,"Mail":8);
  2.  productVersion.deleteKeys({"CRM","Mail"});// deletes the specified keys along with their values
  3.  products=collection("Creator","CRM","Mail");
  4.  products.deleteKeys({1,2});// deletes the elements "CRM" and "Mail"

distinct

The distinct function returns the unique values (from key value pairs), or unique elements, present in a collection.

Return Type

LIST

Syntax

  1. <variable>=<collectionVariable>.distinct();
where,

Examples

  1.  productVersion=collection("Creator":5,"CRM":2,"Mail":5);
  2.  infoproductVersion.distinct();// Returns 5, 2
  3.  products=collection("Creator","CRM","CRM");
  4.  infoproducts.distinct();// Returns "Creator", "CRM"

duplicate

The duplicate function returns the elements present in the given start index (inclusive) and end index (non inclusive). If the indices are not specified, it duplicates and returns the given collection of elements.

Return Type

LIST

Syntax

  1. <variable>=<collectionVariable>.duplicate(<startIndex>,<endIndex>);
where,

Examples

  1.  products1=collection("Creator","CRM","Books");
  2.  info products1.duplicate(0,1);// Returns "Creator"

get

The get function retrieves values from a collection using either an index or a key.
Note: Index starts from 0.

Return Type

ANY DATA TYPE

Syntax

  1. <variable>=<collection>.get(<indexValue>);
(OR)
  1. <variable>=<collection>.get(<key>);


Examples

  1.  names = Collection("name10","name2","name6","name1");
  2.  first_name = names.get(0);// the value "name10" is assigned to first_name
  3.  fifth_name = names.get(4);// Throws a run-time error - "Given index 4 is greater than the list size"

  4.  names= Collection("name1":"John","name2":"Bill");
  5.  name = names.get("name1");// the value "John" is assigned to name
  6.  name = names.get("name3");// returns null

getAsString

The getAsString function fetches an element from a collection as a text value.

Return Type

TEXT

Syntax

  1. <variable>=<collection>.getAsString(<index>);
where,

Examples

  1.  product_name=Collection();
  2.  product_name="123,456,120,120.46";
  3.  index2=product_name.getasstring(2);// The number 120 gets stored in index2 as a 'text' value

getKey

The getKey function returns the key of a specified value, or the index of a specified element, in a collection.

Return Type

  1. Data type of the return value will depend on the data type of the key.
  2. Returns null if the specified value is not found.
  3. Data type is NUMBER if the index of an element is returned. Returns -1 if the specified element is not found.

Syntax

To get the key of a specified value:
  1. <variable>=<collectionVariable>.getKey(<value>);
(OR)
To get the index value of an element:
  1. <variable>=<collectionVariable>.getKey(<element>);
where,


Examples

  1.  productVersion=collection("Creator":5,"CRM":2,"Mail":8);
  2.  product=productVersion.getKey(5);
  3.  info product;// Returns "Creator"
  4.  products=Collection("Creator","CRM","Mail");
  5.  indexNum=products.getKey("CRM");
  6.  info indexNum;// Returns 1

getLastKey

The getLastKey function returns the key of a specified value's last occurrence, or the index of a specified element's last occurrence, in a collection.

Return Type

  1. Data type of the return value will depend on the data type of the key.
  2. Returns null if the specified value is not found.
  3. Data type is NUMBER if the index of an element is returned. Returns -1 if the specified element is not found.

Syntax

To get the key of a specified value's last occurrence:
  1. <variable>=<collectionVariable>.getLastKey(<value>);
(OR)
To get the index value of an element's last occurrence:
  1. <variable>=<collectionVariable>.getLastKey(<element>);
where,

Examples

  1.  productVersion=collection("Creator":5,"CRM":2,"Mail":5);
  2.  info productVersion.getLastKey(5);// Returns "Mail"
  3.  products=collection("Creator","CRM","Creator");
  4.  info products.getLastKey("Creator");// Returns 2


insert

The insert function adds specified elements or key-value pairs to a collection.
Note: You cannot add key-value pairs into an index-value type collection or elements into a key-value type collection.

Syntax

To insert key-value pairs:
  1. <collectionVariable>.insert(<key>:<value>);
(OR)
To insert elements:
  1. <collectionVariable>.insert(<element>);
where,

Examples

  1.  products=collection("Creator","CRM","Campaigns");
  2.  products.insert("Analytics");// inserts "Analytics" to the existing collection
  3.  productVersion=collection("Creator":5);
  4.  productVersion.insert("CRM":5);// inserts the new key value pair to the existing collection

insertAll

The insertAll function adds a list of specified elements or key-value pairs to a collection.

Syntax

To insert key-value pairs:
  1. <collectionVariable>.insertAll(<keyValueList>);
(OR)
To insert elements:
  1. <collectionVariable>.insertAll(<elementList>);
where,

Examples

  1.  products=collection("Creator","CRM","Campaigns");
  2.  products.insertAll({"Analytics","Connect"}); // inserts "Analytics" and "Connect" to the existing collection
  3.  productVersion=collection("Creator":5);
  4.  productVersion.insertAll({"CRM":5,"Campaigns":2});// inserts the new key-value pairs to the existing collection

intersect

The intersect function returns the common elements present in two given collections.

Return Type

DECIMAL

Syntax

  1. <variable>=<collectionVariable1>.intersect(<collectionVariable2>);
where,

Examples

  1.  products1=collection("Creator","CRM","Books");
  2.  products2=collection("Creator","CRM","Mail");
  3.  info products1.intersect(products2);// returns "Creator", "CRM"

isEmpty

The isEmpty function takes an expression as argument. It returns true if the value resolved by the expression is empty. Otherwise, it returns false.
Note: Please refer to the differences between isBlank(), isNull() and isEmpty() and how data can be validated.

Return Type

BOOLEAN

Syntax

  1. <variable> = <expression>.isEmpty();
where,

Examples

  1.  listVar={"Projects","Mail",{"Zoho Creator","Zoho CRM"}};
  2.  info listVar.isEmpty();//returns false
  3.  collVar=Collection();
  4.  info collVar.isEmpty();//returns true
  5.  mapVar=Map({"key1":"value1","key2":"value2"});
  6.  mapVar={};
  7.  info mapVar.isEmpty();//returns true
  8.  textVar=" ";
  9.  info textVar.isEmpty();//returns false

keys

The keys function returns the keys (from key value pairs), or elements, present in a collection.

Return Type

LIST

Syntax

  1. <variable>=<collectionVariable>.keys();
where,

Examples 

  1.  productVersion=collection("Creator":5,"CRM":2,"Mail":8);
  2.  info productVersion.keys();// returns "Creator", "CRM", "Mail"
  3.  products=collection("Creator","CRM","Mail");
  4.  info products.keys();// returns "Creator", "CRM", "Mail"

percentile

The percentile function takes a numerical value 'n' as argument, and returns the nth percentile in a collection of values
Note:
This task is applicable to all services except Zoho Creator.
A percentile is a value below which a given percentage of values in a data set fall.

Return Type

NUMBER/DECIMAL

Syntax

  1. <variable>=<collection>.percentile(<n>);
where,

Examples

Let's consider a collection of numerical values. Calculating the 50th percentile of the collection of numbers.
  1.  marks=Collection(300,455,124,926,780);
  2.  info marks.percentile(50); // returns 455

Percentile calculation:

  1. Multiply the percentile (50 in this case)to be calculated with the number of elements (5 in this case).
  2. Dividing the product by 100, we get 2.5 (50*5/100 = 2.5)
  3. Rounding up the result to the nearest whole number, we get 'n' (3).
  4. Ordering the collection in ascending order, we get {124,300,455,780,926}.
  5. Find the n'th (3rd) value from the collection. 455 is the 50th percentile for the collection.

size

The size function returns the number of values or elements present in a collection.

Return Type

NUMBER

Syntax

  1. <variable>=<collectionVariable>.size();
where,

Examples

  1.  productVersion=collection("Creator":5,"CRM":2,"Mail":8);
  2.  info productVersion.size(); // Returns 3
  3.  products=collection("Creator","CRM","Mail");
  4.  info products.size();// Returns 3

sort

The sort function sorts the elements, or key value pairs based on values in a collection.

Syntax

  1. <collectionVariable>.sort(<booleanValue>);
where,

Examples

  1.  productVersion1=collection("Creator":5,"CRM":2,"Mail":8);
  2.  productVersion1.sort();// collection becomes {"CRM":2,"Creator":5,"Mail":8}
  3.  productVersion2=collection("Creator","CRM","Mail");
  4.  productVersion2.sort(false);// collection becomes {"Mail", "Creator", "CRM"}

sortKey

The sortKey function sorts the keys in a collection containing key-value pairs.

Syntax

  1. <collectionVariable>.sortKey(<booleanValue>);
where,

Examples

  1.  productVersion=collection("Creator":5,"CRM":2,"Mail":8);
  2.  productVersion.sortKey();// Collection becomes {"CRM":2,"Creator":5,"Mail":8}


toCollection

The toCollection function takes an expression as an argument, and returns a collection.

Return Type

COLLECTION

Syntax

  1. <variable>=<expression>.toCollection();
where,

Examples

  1.  products = "{company:Zoho, product:Deluge}";
  2.  info products.toCollection(); // Returns the collection as a key-value pair - {"product":"Creator","company":"Zoho"}
  3.  products = "{company, Zoho, product, Deluge}";
  4.  info products.toCollection(); // Returns the collection as a list - "product,Creator,company,Zoho"

update

The update function updates a specified value of a key or a specified element in a collection.

Syntax

To update the value of a key:
  1. <collectionVariable>.update(<key>,<updateValue>);
(OR)
To update an element:
  1. <collectionVariable>.update(<elementIndex>,<updatedValue>);
where,

Examples

  1.  products=collection("Creator","CRM","Campaigns");  
  2.  products.update("2","Analytics");//replaces "Campaigns" with "Analytics"
  3.  productVersion=collection("Creator":5,"CRM":2)
  4.  productVersion.update("CRM",3);// replaces the value 2 with 3

values

The values function returns the values (from key value pairs), or elements, present in a collection.

Return Type

LIST

Syntax

  1. <variable>=<collectionVariable>.values();
where,

Examples

  1.  productVersion=collection("Creator":5,"CRM":2,"Mail":8);
  2.  info productVersion.values(); // Returns 5, 2, 8
  3.  products=collection("Creator","CRM","Mail");
  4.  info products.values();// Returns "Creator", "CRM", "Mail"

notContains

Overview
The notContains() function takes inputValue and searchValue as arguments. It returns true if the inputValue does not contain the searchValuet. Otherwise, it returns false.
Note: This function performs a case-sensitive search.

Return Type

Boolean

Syntax

  1. <variable> = <inputValue>.notcontains( <searchValue> );
(OR)
  1. <variable> = notContains(<inputValue>, <searchValue> );


Examples

  1.  /*The notContains() function on TEXT input value*/
  2.  products="Zoho Creator";
  3.  boolVal=products.notContains("Creator");// returns false
  4.  
  5.  /*The notContains() function performs a case-sensitive search*/
  6.  products = "Zoho Creator";
  7.  boolVal = products.notContains("CREATOR");// returns true
  8.  
  9.  /*The notContains() function on LIST*/
  10.  products =List();
  11.  products.add("Creator");
  12.  products.add("CRM");
  13.  products.add("Cliq");
  14.  boolVal = products.notContains("Books");// returns true
  15.  
  16.  /*The notContains() function on MAP input value*/
  17.  product_details = Map();
  18.  product_details.put("product","Creator");
  19.  product_details.put("subscription","yearly");
  20.  boolVal = product_details.notContains("price");// returns true
  21.  
  22.  /*The notContains() function on index-value Collection*/
  23.  products = Collection();
  24.  products.insert("Creator");
  25.  products.insert("CRM"); boolVal = products.notContains("Cliq");// returns true
  26.  
  27.  /*The notContains() function on key-value collection*/
  28.  product_details = Collection();
  29.  product_details.insert("product","Creator");
  30.  product_details.insert("subscription","yearly");
  31.  boolVal = product_details.notContains("subscription");// returns false
 



    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

                                                                                                  • Data Access - Collection variable

                                                                                                    This guide will help you with the following: Overview Declaring a collection variable Aggregate functions Fetch field value from the first record Fetch values of a field from all the records in a collection Updating field value in a collection ...
                                                                                                  • 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 ...
                                                                                                  • Logical Functions

                                                                                                    The guide helps you with the following: 1. Difference between isBlank(), isNull() and isEmpty() functions 2. Equals 3. isBlank 4. isEmpty 5. isNull 6. isValidObject Difference between isBlank(), isNull() and isEmpty() functions The table below lists ...
                                                                                                  • XML and JSON functions

                                                                                                    Difference between getJson and get The major difference between getJson and get functions is the type of data on which the two functions work. The getJson function is meant to be performed on TEXT type which is in json or key-value format. The get ...
                                                                                                  • Functions

                                                                                                    This guide helps you with the following: Create Functions  Normal Functions REST API Functions Invoke Functions  Edit Functions  Delete Functions Rest API Functions Authentication Version 2.0 Version 1.0 Example Comparison of Version 2.0 and 1.0 ...
                                                                                                    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