Friday, January 15, 2016

Formula Functions for Cumulus 10

var ( variable-name [, value ] )

This pseudo-function either sets a variable to a given value or returns the current variable value. A variable can be get and set multiple times.

The last formula expression (following the var() setter functions) then returns the value of the whole expression. There is no specific separator necessary after each var() setter function.

Returns: The variable value



subtableitems ( result-table-spec, query-string, sort-fields, sort-directions, limit-offset, limit-count )

Returns a "collection" type value that can be used as parameter to other functions (but not as a field value). The collection is created for the given result-table-spec containing items that match the given query.

The collection is then sorted by the given sort fields (comma-separated list of field-specs) and the sort-directions (comma-separated list of "ascending"/"descending". The collection is then limited to only contain up to limit-count items starting at offset limit-offset.

The result-table-spec needs to be a sub-table of the current item's table because the query is always extended with a condition to match the item ID as the "Host Item ID".

Returns: The collection object



itembyindex ( collection-object, index )

Returns an "item" type value that can be used as parameter to other functions (but not as a field value). The index parameter specifies the index of the item inside the collection object specified. An index of 0 returns the first item, 1 the second item, etc. A negative index returns an item counting from the end of the collection: -1 returns the last item, -2 the item before the last one etc.

Returns: The item object (or null if there is no such item)



fieldvalue ( field-spec [, item-object] [, as-string] )

Variant of the existing function that returns the value of the field specified for the given item object. The item object is the result of the itembyindex() function.

Returns: The field value (any type)



fieldhasvalue ( field-spec [, item-object])

Variant of the existing function that returns whether the field specified for the given item object has a value or not. The item object is the result of the itembyindex() function.

Returns: A boolean telling whether the field has a value or not



sum (collection-object, field-spec)

Calculates the sum of all values in the field specified by "field-spec" in all items of the "collection-object". Empty field values are skipped.

Returns: The sum of all values (integer or real)



average (collection-object, field-spec)

Calculates the average of all values in the field specified by "field-spec" in all items of the "collection-object". Empty field values are skipped. For Rating type fields the average needs to build the average of the number of stars whereas the field value itself is just the ID.

Returns: The average value (integer or real)



median (collection-object, field-spec)

Picks the median of all values in the field specified by "field-spec" in all items of the "collection-object". Empty field values are skipped.

Returns: The median value (integer or real)



min (collection-object, field-spec)

Variant of the existing function that calculates the minimum of all values in the field specified by "field-spec" in all items of the "collection-object". Empty field values are skipped.

Returns: The minimum value (integer or real)



max (collection-object, field-spec)

Variant of the existing function that calculates the maximum of all values in the field specified by "field-spec" in all items of the "collection-object". Empty field values are skipped.

Returns: The maximum value (integer or real)



count (collection-object)

Count the number of items of the "collection-object".

Returns: The number of items (integer)