<< Click to Display Table of Contents >> Filtering, sorting and other functions with collections |
Overview
When you use functions in expressions that return a collection (BizagiArrayList), you can use other functions on that object that help to filter, sort, or get a subset of records.
The functions described in this article only apply for a Bizagi Array List Object type. Please understand the difference between all types of arrays in the following article, see Iterating using expressions. |
Object containing the collection
You can use any of the following functions to get records on a collection:
•CHelper.GetValueAsCollection("CollectionXpath")
•Me.getXPath("entity-list('','')",parameters)
•Me.getXPath("CollectionXpath")
•<CollectionXpath>
For example you can declare a variable object type containing a collection like this:
var CollectionObject = CHelper.GetValueAsCollection(<ProcessEntity.Collection>);
now you can use the CollectionObject with the following functions:
•filter
•sort
•distinct
•sum
Filter
This function returns a collection (BizagiArrayList) considering the filter condition.
Syntax: CollectionObject.filter("Condition");
Condition: String with filter conditions.
Returns: Collection (BizagiArrayList)
Example:
var CollectionObject = CHelper.GetValueAsCollection(<ProcessEntity.Collection>);
var FilteredCollection = CollectionObject.filter("Attribute1 = ‘Value’ AND RelatedAttribute.Attribute2 != null");
You can use the same operators considered in filtering xpath.
Sort
This function returns a collection (BizagiArrayList) ordered by the attribute defined.
Syntax: CollectionObject.sort("sortingAttribute");
Sorting attribute: attribute of the collection to sort .
Returns: Collection (BizagiArrayList)
Example:
var CollectionObject = CHelper.GetValueAsCollection(<ProcessEntity.Collection>);
var SortedCollection = CollectionObject.sort("Attribute1");
This function only sorts in ascending order.
Distinct
This function returns an ArrayList with no repeated values of a column in the collection, defined with the associated attributed of the column.
Syntax: CollectionObject.distinct("Attribute");
Attribute: attribute of the collection to define as the column to get non-repeated values.
Returns: Arraylist.
Example:
var CollectionObject = CHelper.GetValueAsCollection(<ProcessEntity.Collection>);
var DistinctArray = CollectionObject.distinct("Attribute");
Because this function returns an Arraylist, and not a collection, the iteration must be handled as such. See how to iterate an array list.
for (var i = 0; i < DistinctArray.Count; i++){
//Get the object that contains the row
ArrayObjectRow = DistinctArray[i];
}
Sum
This function returns the sum of all numeric values in a collection column.
Syntax: CollectionObject.sum("NumericAttribute");
Numeric Attribute: attribute of the collection to sum its values.
Returns: Numeric object type.
Example:
var CollectionObject = CHelper.GetValueAsCollection(<ProcessEntity.Collection>);
var sum = CollectionObject.sum("Attribute");
Last Updated 10/26/2022 9:47:30 AM