Move Collection Item If
Verb: collectionMoveIf
Moves items from one collection to another if the specified condition is met.
Collections are enumerable data structures that can be accessed using indexes and keys.
Syntax
collectionMoveIf --target(List<Variant>) --collection(List<Variant>) --operator(ConditionalOperators) --value(Variant) [--negate(Boolean)]
Inputs
Script | Designer | Required | AcceptedTypes | Description |
---|---|---|---|---|
--target | Target Collection | Required | List<Any>, String Dictionary<Any> | Collection that receives the moved items. |
--collection | Collection | Required | List<Any>, String Dictionary<Any> | Collection containing the items that should be evaluated and moved to another collection. |
--operator | Operator | Required | ConditionalOperators | Rule used to evaluate the condition. Options:
|
--value | Value | Only whenOperator is Equal_To, Greater_Than, Greater_Than_Equal_To, Less_Than, Less_Than_Equal_To, Contains, Ends_With, Begins_With, Matches | Any | Value used to evaluate each item in the collection according to Operator. |
--negate | Negate | Optional | Boolean | Negates the rule in Operator. |
Example
Example 1: Moves items containing the letter "a" from one List to another using the Contains condition.
defVar --name targetCollection --type List --innertype String
defVar --name namesCollection --type List --innertype String --value "[Victor,John,Marcos,Lucas]"
//Moves items in "$ {namesCollection}" containing the letter "a" to "$ {targetCollection}".
collectionMoveIf --target "${targetCollection}" --collection "${namesCollection}" --operator "Contains" --value a
logMessage --message "${targetCollection}" --type "Info"
//The result of $ {targetCollection} after the condition is executed is: [Marcos, Lucas].
Example 2: Moves items that do not contain the letter "a" from one List to another using the Contains condition and the Negate parameter.
defVar --name targetCollection --type List --innertype String
defVar --name namesCollection --type List --innertype String --value "[Victor,John,Marcos,Lucas]"
//Moves the values contained in "${namesCollection}" that do not contain the letter "a" to "${targetCollection}".
collectionMoveIf --target "${targetCollection}" --collection "${namesCollection}" --operator "Contains" --value a --negate
logMessage --message "${targetCollection}" --type "Info"
//The result of ${targetCollection} after the condition is executed is: [Victor, John].
Remarks
The collection given in the Collection parameter must be of the same type as the Target Collection parameter collection.