# Functions

XPath provides a series of functions that help you perform calculations over collections in an easy and intuitive way.

These functions are available through the Expressions functions. These are NOT all the functions available, just ones that help you navigate and work Xpaths.

Basic Functions

 FUNCTION DESCRIPTION SYNTAX And Compares two Booleans that can be XPath or the result of another XPath function. It returns true if they are both true. Otherwise it returns false. Avg Obtains the average of elements in a collection. The attribute to average must be number or currency. Count Counts the number of elements in a collection. Empty Returns True when a collection is EMPTY and False otherwise. Equals Compares two XPath arguments and returns true if they are equivalent. The parameters can be either XPath expressions or XPath functions. Exist Returns True when the collection has at least one element and False otherwise. Greater than Compares two XPath arguments and returns true if the first one is greater than the second one. It returns false otherwise. The parameters can be either XPath expressions or XPath functions that return integers, decimals, currency and dates. Greater than or equals to Compares two XPath arguments and returns true if the first one is greater than or equal to the second one The parameters can be either XPath expressions or XPath functions that return integers, decimals, currency or dates. Is Empty Returns true if a string-type attribute is null or empty. Returns false otherwise. Is False Evaluates an XPath expression or the result of an XPath function. It returns true if the parameter is false. Otherwise it returns false. Is not Empty Returns true if a string-type attribute is filled. Returns false otherwise. Is not Null Returns true if any attribute is filled (not null). Returns false otherwise. Is Null Returns true if any attribute is null (not filled). Returns false otherwise. Is True Evaluates an XPath expression or the result of an XPath function. It returns true if the parameter is true. Otherwise it returns false. Less than Compares two XPath arguments and returns true if the first one is less than the second one. The parameters can be either XPath expressions or XPath functions that return integers, decimals, currency or dates. Less than or equals to Compares two XPath arguments and returns true if the first one is less than or equal to the second one. The parameters can be either XPath expressions or XPath functions that return integers, decimals, currency or dates. Like Compares two parameters and returns true if the second one is included in the first one. The parameters can be string XPath or strings. When using fixed strings define them between single quotes ('). When any of the parameters is empty the function will return True. Max Obtains the maximum value within the elements of a collection. The attribute must be number or currency. Min Obtains the minimum value within the elements of a collection. The attribute must be number or currency. Not equals Compares two XPath arguments and returns true if they are NOT equivalent. The parameters can be either XPath expressions or XPath functions Or Compares two Booleans  that can be XPath expressions or the result of another XPath function. It returns False when both parameters are false. Otherwise it returns True. Sum Adds the elements of a collection. The attribute to add must be number or currency.

Collection functions

 FUNCTION DESCRIPTION SYNTAX New collection item Allows the inclusion of a new item (record) to a collection. The item is initially included as a blank entry. You can assign a variable to set values to the new record. Me.newCollectionItem("XPath")   The XPath must be a collection Attach collection item Allows to attach ONE item (record) from one collection to another collection. The item is not duplicated, it is shared by both collections. Both collections must belong (be related) to the same entity. Me.attachCollectionItem("XPath", item)   The XPath must be the collection that will receive the item. The item is the XPath of the record that will be attached. Attach collection items Allows to attach one or more items (records)  from one collection to another collection. The items are not duplicated, they are shared by both collections. Both collections must belong (be related) to the same entity. Me.attachCollectionItems("XPath", items)   The XPath must be the collection that will receive the items. The items are the Xpaths of the records that will be attached. Detach collection item Allows detaching (disconnecting) ONE item (record) from a collection. The item will no longer be a part of the collection but it will not be deleted from the database. Me.detachCollectionItem("XPath", item)   The XPath must be the collection that will lose the item. The item is the XPath of the record that will be detached. Detach collection items Allows detaching (disconnecting) one or more items (records) from a collection. The items will no longer be a part of the collection but they will not be deleted from the database. Me.detachCollectionItems("XPath", items)   The XPath must be the collection that will lose the items. The items are the Xpaths of the records that will be detached. Detach all collection items Allows detaching (disconnecting) ALL items (records) from a collection. The items will no longer be a part of the collection but they will not be deleted from the database. Me.detachAllCollectionItems("XPath")   The XPath must be the collection that will lose the items. Delete one collection item Allows the complete deletion of ONE item (record) of a collection. The item will be deleted from the collection and from the database. Me.deleteCollectionItem("XPath", item)   The XPath must be a collection, and the item ONE record of the collection. This item must be ONE and only ONE. If not, the function will fail. Delete collection items Allows the complete deletion of one or more items (records) of a collection. The items will be deleted from the collection and from the database. Me.deleteCollectionItems("XPath", item)   The XPath must be a collection, and the items one or more records of the collection Delete all collection items Allows the complete deletion of ALL items (records) of a collection. The items will be deleted from the collection and from the database. Me.deleteAllCollectionItems("XPath")   The XPath must be a collection. Distinct-values Returns the a list (not a collection) with non repeated values of a specific attribute, from a collection. It is necessary to indicate the attribute to find the distinct values from. The list with the non repeated values will be entries of this attribute. The XPath must be a collection, that navigates util reaching an attribute of the collection that can be used to find non repeated values. Get value as collection Transforms a list of values stored as a text chain into an array list. In some cases it is necessary to handle Collections in expressions without using the Iterate over XPath functionality to allow a complete manipulation of the code. CHelper.GetValueAsCollection()   The XPath must be a collection Sort Sorts the records of a collection in ascending order according to an attribute. It is possible to sort using an integer, float, date or string attribute.  The method receives a collection, and returns the collection sorted by the attributeâ€™s value. ;   The XPath must be a collection Add relation DEPRECATED DEPRECATED: Use newCollectionItem("XPath"); DEPRECATED: Use newCollectionItem("XPath"); Remove relation DEPRECATED DEPRECATED: Use deleteCollectionItems("XPath"); DEPRECATED: Use deleteCollectionItems("XPath");

Math Functions

 FUNCTION DESCRIPTION SYNTAX Abs Returns the absolute value of a number (integer,currency, real, float). Abs(1.5)  -> 1.5 Abs(-1.5) -> 1.5 The parameter can be Xpath, variable or number. CHelper.Math.Abs(Number) Average Obtains the average (arithmetic mean) of a set of numbers (integer,currency, real, float). The parameters can be Xpaths, variables or numbers, and have to be between brackets. CHelper.Math.Average([Number1,Number2,......) Ceiling Rounds a number (integer,currency, real, float) up to the nearest integer. Ceiling(1.2) -> 2 Ceiling(1.9) -> 2 The parameter can be XPath, variable or number. CHelper.Math.Ceiling(Number) Exp Returns e (the base of natural logarithms) raised to the given power. The parameter can be Xpath, variable or number. THE RESULT OF THIS FUNCTION MUST BE STORED IN A FLOAT-TYPE ATTRIBUTE. CHelper.Math.Exp(Number) Floor Rounds a number (integer,currency, real, float) down to the nearest integer. Floor(1.2) -> 1 Floor(1.9) -> 1 The parameter can be Xpath, variable or number. CHelper.Math.Floor(Number) IsNaN This function checks if a parameter is not a number: •Returns true if the parameter is not a number.•Returns false if the parameter is a number.The parameter can be Xpath, variable or number. CHelper.Math.IsNaN(Parameter) Ln Returns the natural logarithm of a number (integer,currency, real, float). The parameter can be Xpath, variable or number. CHelper.Math.Ln(Number) Log10 Returns the base 10 logarithm of a number. The parameter can be Xpath, variable or number. CHelper.Math.Log10(Number) Max Returns the largest value of a set of numbers (integer,currency, real, float). The parameters can be Xpaths, variables or numbers, and have to be between brackets. CHelper.Math.Max([Number1,Number2]) Min Returns the smallest value of a set of numbers (integer,currency, real, float). The parameters can be Xpaths, variables or numbers, and have to be between brackets. CHelper.Math.Min[(Number1,Number2]) Module Returns the remainder after a number is divided by a divisor. Mod(8,3) -> 2 Mod(10,2) -> 0 The parameters can be Xpaths, variables or numbers and must be integers. CHelper.Math.Module(Number,Divisor) Percentage Returns the equivalent in percentage of a number (integer,currency, real, float). Percentage(100) -> 1 Percentage( 75)  -> 0.75 The parameter can be Xpath, variable or number. CHelper.Math.Percentage(Number) Pow Obtains the result of a number raised to a power. The parameters can be Xpaths, variables or numbers. CHelper.Math.Pow(Base,Power) Quotient Returns  the integer portion of a division. Quotient(100,3)-> 33 Quotient(5,2)-> 2 The parameters can be Xpaths, variables or numbers and must be integers. CHelper.Math.Quotient(Number,Divisor) Rand(from,to) Returns an integer random number between two numbers. The parameters can be xpaths, variables or numbers and must be integers. CHelper.Math.Rand(ValueFrom,ValueTo) Rand When the function has empty parameters it returns decimal random number between 0.0 to 1.0. CHelper.Math.Rand() Round Reduces a given number (integer,currency, real, float) to a specific number of decimal places (integer). Round (1.247,2) -> 1.25 Round (1.534,1) -> 1.5 The parameters can be Xpaths, variables or numbers. CHelper.Math.Round(Number,DecimalPlaces) Sqrt Obtains the square root of a number (integer,currency, real, float). CHelper.Math.Sqrt(Number) Truncate Truncates a number (integer,currency, real, float) to an integer by removing its decimal, or fractional part. Truncate(35.5) -> 35 Truncate(35.89) -> 35 The parameter can be Xpath, variable or number. CHelper.Math.Truncate(Number)