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
- <collectionVariable>.clear();
where,
Examples
- productVersion=collection("Deluge":5,"CRM":2,"Mail":8);
- productVersion.clear();
- 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:
- <variable>=<collectionVariable>.containsKey(<key>);
(OR)
To check if an index value is present in a collection:
- <variable>=<collectionVariable>.containsKey(<index>);
where,
Examples
- productVersion=collection("Creator":5,"CRM":2,"Mail":8);
- info productVersion.containsKey("CRM"); // Returns true
- productVersion=collection("Creator","CRM","Mail");
- 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
- <variable>=<collectionVariable>.containsValue(<value>);
Examples
- productVersion=collection("Creator":5,"CRM":2,"Mail":8);
- 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:
- <collectionVariable>.delete(<value>);
(OR)
To delete an element:
- <collectionVariable>.delete(<element>);
where,
Examples
- products=Collection("Creator","CRM","Campaigns");
- products.delete("CRM");
- info products;// Returns "Creator,Campaigns"
- productVersion=Collection("Creator":5,"CRM":2);
- productVersion.delete(2);
- 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:
- <collectionVariable>.deleteAll(<valuesList>);
(OR)
To delete elements:
- <collectionVariable>.deleteAll(<elementsList>);
where,
Examples
- products=collection("Creator","CRM","Campaigns");
- products.deleteAll({"CRM","Campaigns"});// deletes the specified elements from the collection
- productVersion=collection("Creator":5,"CRM":2);
- 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:
- <collectionVariable>.deleteKey(<key>);
(OR)
To delete an element based on its index:
- <collectionVariable>.deleteKey( <elementIndex> );
where,
Examples
- productVersion=collection("Creator":5,"CRM":2);
- productVersion.deleteKey("CRM");// deletes the specified key along with its value
- products=collection("Creator","CRM","Campaigns");
- 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:
- <collectionVariable>.deleteKeys(<keysList>);
(OR)
To delete elements based on index values:
- <collectionVariable>.deleteKeys(<indexList>);
where,
Examples
- productVersion=collection("Creator":5,"CRM":2,"Mail":8);
- productVersion.deleteKeys({"CRM","Mail"});// deletes the specified keys along with their values
- products=collection("Creator","CRM","Mail");
- 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
- <variable>=<collectionVariable>.distinct();
where,
Examples
- productVersion=collection("Creator":5,"CRM":2,"Mail":5);
- infoproductVersion.distinct();// Returns 5, 2
- products=collection("Creator","CRM","CRM");
- 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
- <variable>=<collectionVariable>.duplicate(<startIndex>,<endIndex>);
where,
Examples
- products1=collection("Creator","CRM","Books");
- 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
- <variable>=<collection>.get(<indexValue>);
(OR)
- <variable>=<collection>.get(<key>);
Examples
- names = Collection("name10","name2","name6","name1");
- first_name = names.get(0);// the value "name10" is assigned to first_name
- fifth_name = names.get(4);// Throws a run-time error - "Given index 4 is greater than the list size"
- names= Collection("name1":"John","name2":"Bill");
- name = names.get("name1");// the value "John" is assigned to name
- name = names.get("name3");// returns null
getAsString
The getAsString function fetches an element from a collection as a text value.
Return Type
TEXT
Syntax
- <variable>=<collection>.getAsString(<index>);
where,
Examples
- product_name=Collection();
- product_name="123,456,120,120.46";
- 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
- Data type of the return value will depend on the data type of the key.
- Returns null if the specified value is not found.
- 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:
- <variable>=<collectionVariable>.getKey(<value>);
(OR)
To get the index value of an element:
- <variable>=<collectionVariable>.getKey(<element>);
where,
Examples
- productVersion=collection("Creator":5,"CRM":2,"Mail":8);
- product=productVersion.getKey(5);
- info product;// Returns "Creator"
- products=Collection("Creator","CRM","Mail");
- indexNum=products.getKey("CRM");
- 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
- Data type of the return value will depend on the data type of the key.
- Returns null if the specified value is not found.
- 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:
- <variable>=<collectionVariable>.getLastKey(<value>);
(OR)
To get the index value of an element's last occurrence:
- <variable>=<collectionVariable>.getLastKey(<element>);
where,
Examples
- productVersion=collection("Creator":5,"CRM":2,"Mail":5);
- info productVersion.getLastKey(5);// Returns "Mail"
- products=collection("Creator","CRM","Creator");
- 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:
- <collectionVariable>.insert(<key>:<value>);
(OR)
To insert elements:
- <collectionVariable>.insert(<element>);
where,
Examples
- products=collection("Creator","CRM","Campaigns");
- products.insert("Analytics");// inserts "Analytics" to the existing collection
- productVersion=collection("Creator":5);
- 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:
- <collectionVariable>.insertAll(<keyValueList>);
(OR)
To insert elements:
- <collectionVariable>.insertAll(<elementList>);
where,
Examples
- products=collection("Creator","CRM","Campaigns");
- products.insertAll({"Analytics","Connect"}); // inserts "Analytics" and "Connect" to the existing collection
- productVersion=collection("Creator":5);
- 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
- <variable>=<collectionVariable1>.intersect(<collectionVariable2>);
where,
Examples
- products1=collection("Creator","CRM","Books");
- products2=collection("Creator","CRM","Mail");
- 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
- <variable> = <expression>.isEmpty();
where,
Examples
- listVar={"Projects","Mail",{"Zoho Creator","Zoho CRM"}};
- info listVar.isEmpty();//returns false
- collVar=Collection();
- info collVar.isEmpty();//returns true
- mapVar=Map({"key1":"value1","key2":"value2"});
- mapVar={};
- info mapVar.isEmpty();//returns true
- textVar=" ";
- 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
- <variable>=<collectionVariable>.keys();
where,
Examples
- productVersion=collection("Creator":5,"CRM":2,"Mail":8);
- info productVersion.keys();// returns "Creator", "CRM", "Mail"
- products=collection("Creator","CRM","Mail");
- 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
- <variable>=<collection>.percentile(<n>);
where,
Examples
Let's consider a collection of numerical values. Calculating the 50th percentile of the collection of numbers.
- marks=Collection(300,455,124,926,780);
- info marks.percentile(50); // returns 455
Percentile calculation:
- Multiply the percentile (50 in this case)to be calculated with the number of elements (5 in this case).
- Dividing the product by 100, we get 2.5 (50*5/100 = 2.5)
- Rounding up the result to the nearest whole number, we get 'n' (3).
- Ordering the collection in ascending order, we get {124,300,455,780,926}.
- 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
- <variable>=<collectionVariable>.size();
where,
Examples
- productVersion=collection("Creator":5,"CRM":2,"Mail":8);
- info productVersion.size(); // Returns 3
- products=collection("Creator","CRM","Mail");
- info products.size();// Returns 3
sort
The sort function sorts the elements, or key value pairs based on values in a collection.
Syntax
- <collectionVariable>.sort(<booleanValue>);
where,
Examples
- productVersion1=collection("Creator":5,"CRM":2,"Mail":8);
- productVersion1.sort();// collection becomes {"CRM":2,"Creator":5,"Mail":8}
- productVersion2=collection("Creator","CRM","Mail");
- productVersion2.sort(false);// collection becomes {"Mail", "Creator", "CRM"}
sortKey
The sortKey function sorts the keys in a collection containing key-value pairs.
Syntax
- <collectionVariable>.sortKey(<booleanValue>);
where,
Examples
- productVersion=collection("Creator":5,"CRM":2,"Mail":8);
- 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
- <variable>=<expression>.toCollection();
where,
Examples
- products = "{company:Zoho, product:Deluge}";
- info products.toCollection(); // Returns the collection as a key-value pair - {"product":"Creator","company":"Zoho"}
- products = "{company, Zoho, product, Deluge}";
- 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:
- <collectionVariable>.update(<key>,<updateValue>);
(OR)
To update an element:
- <collectionVariable>.update(<elementIndex>,<updatedValue>);
where,
Examples
- products=collection("Creator","CRM","Campaigns");
- products.update("2","Analytics");//replaces "Campaigns" with "Analytics"
- productVersion=collection("Creator":5,"CRM":2)
- 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
- <variable>=<collectionVariable>.values();
where,
Examples
- productVersion=collection("Creator":5,"CRM":2,"Mail":8);
- info productVersion.values(); // Returns 5, 2, 8
- products=collection("Creator","CRM","Mail");
- 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
- <variable> = <inputValue>.notcontains( <searchValue> );
(OR)
- <variable> = notContains(<inputValue>, <searchValue> );
Examples
- /*The notContains() function on TEXT input value*/
- products="Zoho Creator";
- boolVal=products.notContains("Creator");// returns false
-
- /*The notContains() function performs a case-sensitive search*/
- products = "Zoho Creator";
- boolVal = products.notContains("CREATOR");// returns true
-
- /*The notContains() function on LIST*/
- products =List();
- products.add("Creator");
- products.add("CRM");
- products.add("Cliq");
- boolVal = products.notContains("Books");// returns true
-
- /*The notContains() function on MAP input value*/
- product_details = Map();
- product_details.put("product","Creator");
- product_details.put("subscription","yearly");
- boolVal = product_details.notContains("price");// returns true
-
- /*The notContains() function on index-value Collection*/
- products = Collection();
- products.insert("Creator");
- products.insert("CRM"); boolVal = products.notContains("Cliq");// returns true
-
- /*The notContains() function on key-value collection*/
- product_details = Collection();
- product_details.insert("product","Creator");
- product_details.insert("subscription","yearly");
- boolVal = product_details.notContains("subscription");// returns false