Smart Buttons
Controls/XML Elements
Manage Collection <ManageCollection>
This control can:
-
Extract a specific element from a collection (minimum number, maximum number, last element, first element).
-
Calculate the number of elements in a collection or average of all numeric elements in the collection (count).
-
Filter from a collection to include only unique elements.
Configuring
You can configure ManageCollection in the Smart Buttons Editor using either the Manage Collection XML Generator or XML.
Configuring with the Smartpoint Buttons XML Generator
To configure with the Smart Buttons XML Generator:
-
Open the Smart Buttons Editor to create a script.
-
Click Manage Collection <ManageCollection> to display the Manage Collection Editor.
-
Configure the attributes.
These examples of collections of elements are used in the following descriptions:
-
Collection1
Simple collection: ABC;30;50;80;2;ABC;2;HK90 -
Collection2
Collection type Value**Key: IBM**49;Mats**80; Cola**36;Trax**390;Mats**7; Cola**36 -
Collection3
Collection type Value**Key: 2**Lufthansa;1**Austrian;0**Aeroflot;5**AmericanAirlines
Attribute
Description
Variable name Mandatory field. Enter the name of that variable that will store the result from the control.
Action type Click the arrow to select the action to perform on the collection.
The following examples apply to the action descriptions:
-
Collection1
Simple collection: ABC;30;50;80;2;ABC;2;HK90 -
Collection2
Collection type Value**Key: IBM**49;Mats**80; Cola**36;Trax**390;Mats**7; Cola**36
Available action types:
-
Count
Returns number of elements in the collection. For example, Collection1 returns a count of "8". -
Last
Returns the last element in the collection. For example, Collection1 returns "HK90". -
First
Returns the first element in the collection. For example, Collection1 returns "ABC". -
Sum
Returns the sum of all elements that are numbers. (Text elements are ignored.) For example, Collection1 returns "164" (30+50+80+2+2). -
Maximum
Returns the the highest number in the collection. (Text elements are ignored.) For example, Collection1 returns "80". -
Minimum
Returns the the highest number in the collection. (Text elements are ignored.) For example, Collection1 returns "2".
-
Average
Returns the average of all numbers in the collection. (Text elements are ignored.) For example, Collection1 returns "32,8" ((30+50+80+2+2):5). -
OperateOn
If the collection is Key**Value type, you may want to operate only on Value or only on Key. For example, to find a maximum number, but only within the Value part of the elements. By default, the complete element is considered.More InformationThis attribute does not work with some of ActionTypes, as this has no logical sense – see table below
Value – operate only on element’s Value, for example, in Collection3 ActionType-Maximum +OperateOn- Value will return 5 (The maximum number within the Value part among all elements is 5)
Key- operate only on element’s Key, for example, in Collection2 ActionType-Sum +OperateOn-Key will return 598 (49+80+36+390+7+36)
*** Attribute “OperateOn” will only work if attribute “ActionType” is set up (see below table which ActionTypes work with OperateOn attribute). If “ActionType” is not set up “OperateOn” attribute will be ignored. ***
*** Attribute “OperateOn” will only work for Value**Key collection. For Simple collection it will be ignored***
Return In case of Value**Key collection, select to return back to the variable:
-
ValueKey: All elements to the agent (ValueKey)
-
Value: Only values
-
Keys: Only keys
Note: @Return works only for Value**Key collections. For Simple collections, it is ignored.
ValueKeyReturns the entire element to the variable. For example in Collection2:
ActionType-Maximum +OperateOn- Key + Return-ValueKey returns Trax**390. The highest (maximum) Key is 390, so it returns the entire element Trax**390.
ValueReturns to the variable Value. For example, in Collection2:
ActionType-First + Return-Value returns IBM. The first element in the collection is IBM**49, so the element Value part, IBM, is returned.
KeyReturns to the variable Key. For example, in Collection3:
ActionType-Minimum +OperateOn-Value+ Return- Key returns Aeroflot. The element with the lowest (minimum) Value part is 0**Aeroflot, so its associated Key is returned: Aeroflot.
FilterUnique Filters the collection and return only unique elements. In Collection1:
-
Unique elements are: 30;50;80;2;ABC;HK90
-
“ABC” and “2” display twice in the collection and are filtered out.
NoChangesIf set up, no filtration will be done. To have the same result you may also remove “FilterUnique” attribute from the code.
ElementFilter and return collection of unique elements (in case of Value**Key collection will read entire element Value+Key), eg. in Collection 1 it would be: 30;50;80;2;ABC;HK90 (one “2” and “ABC” have been filtered out)
KeyIn case of Value**Key collections you may want to filter out from your collection only elements that has the same Key, eg. Original Collection: 1**KELLY;2**KELLY;2**JOHN;3;KATE
Collection after filtration by Key: 1**KELLY;2**JOHN;3;KATE (Second element 2**KELLY has been filtered out as the Key part is the same as in the first element)
Valuein case of Value**Key collections you may want to filter out from your collection only elements that has the same Value, eg. Original Collection: IBM**49;Mats**80; IBM**54654;
Collection after filtration: IBM**49;Mats**80 ( last element IBM**54654 has been filtered out as it has the same Value part (IBM) as the first element in the collection)
Important to remember!
If you use both @FilterUnique and @ActionType, @FilterUnique always runs first to filter the original collection. @ActionType then runs on the already filtered collection. For example:
Collection: APPLES;PEARS,KIWI;APPLES
ActionType:Last
+
FilterUnique:Element
=
Result: KIWI
After the first (@FilterUnique) filtration is completed, the last item, APPLES, is filtered out as duplicated, and collection is changed to APPLES;PEARS,KIWI. Then, ActionType filters out the Last element, and last item in the filtered collection is KIWI.
-
Important!
@ActionType can be used with “Return” and “OperateOn” only as noted.
For example, ActionType:Last and Return can be used together, but ActionType:Count and Return cannot be used together (@Return is ignored).
Configuring with XML
If you want to enter the XML code directly in the Smart Buttons Editor, use the following structure for the XML element.
<ManageCollection VarName="" ActionType="First" OperateOn="" Return="" FilterUnique="">
Tip! You can add the XML code directly to the editor by dragging and dropping the blue button for this control.
Examples
The following examples use the ManageCollection XML element in the script.
Example 1
Extracts the lowest number from a collection.
The collection is a Simple type and the values are static.
<ManageCollection VarName="LowestElement" ActionType="Minimum"> 213;10;8788;2902;892;ABC7</ManageCollection>
Because ActionType-Minimum is selected, the control returns the lowest number (10), and ignores elements that are not numbers. In this example, element: ABC7 is text, not a number, because it contains both letters and numbers.
Example 2
Requests the number of unique notepad remarks in a Booking File.
The following script creates a collection of all notepad remarks with GetString control, and then filters unique items (first) and the count of elements in collection(2) with the ManageCollection control.
<ButtonConf ButtonName="Notepads" Description="" QuickCommand="">
<RunCommand>*NP</RunCommand>
<GetString VarName="AllNotepads"><![CDATA[\d\. (.*) (?:.{2} \d{2}[A-Z]{3} [0-9]{4}Z)]]></GetString>
<ManageCollection VarName="NumberOfUniqueNotepads" ActionType="Count" FilterUnique="Element">[AllNotepads]</ManageCollection>
<ShowMessage>The number of unique notepads in this PNR is: [NumberOfUniqueNotepads]</ShowMessage>
</ButtonConf>
In this example, there are five notepad remarks, but two of the remarks (4 and 5) have the same value. Therefore, the last remark (5) is filtered out and the final number of unique elements in the collection is four.
Example 3
Reads customer name and customer balance from an Excel file (collection type Value**Key) and find display the name of customer with the lowest “customer balance”.
The Excel file:
The script reads the Excel file and selects the customer with the lowest Customer Balance:
<ButtonConf ButtonName="Manage collection" Description="" QuickCommand="">
<ShowMessage>[CustNumAndCustbalance]</ShowMessage>
<ManageCollection VarName="CustomerWithLowestBalance" ActionType="Minimum" OperateOn="Key" Return="Value">[CustNumAndCustbalance]</ManageCollection>
<ShowMessage>[CustomerWithLowestBalance]</ShowMessage>
</ButtonConf>
First, the script reads the Excel file with ReadFromExcel XML element, then shows the collection in a message box with ShowMessage XML element.
Because this collection is a Value**Key collection, each element of the collection contains two parts:
-
Value - Customer Name
-
Key - Customer Balance.
Next, the ManageCollection element determines which part to operate on (@OperateOn). To operate only on the Customer Balance (calculate the minimum Customer Balance), OperateOn="Key" is used. In this control, to return the Customer Name (Value) with the lowest balance, instead of the amount of the Customer Balance, Return="Value" is selected.
The last control is ShowMessage, which displays the final result - the name of the customer with the lowest customer balance: