Copy Collection Items If
Verb: collectionCopyIf
Copies 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
collectionCopyIf --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 copied items. |
--collection | Collection | Required | List<Any>, String Dictionary<Any> | Collection that contains the items that should be evaluated and copied to another collection. |
--operator | Operator | Required | ConditionalOperators | Rule used to evaluate the condition as true or false. 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 by Operator to evaluate each item in the collection. |
--negate | Negate | Optional | Boolean | Negates the rule defined in the Operator. |
Example
Example 1: Copies the items from one list to another based on the condition defined with the Less than operator.
defVar --name targetCollection --type List --innertype String
defVar --name valuesCollection --type List --innertype String --value "[Name,Age,Phone]"
collectionCopyIf --target "${targetCollection}" --collection "${valuesCollection}" --operator "Less_Than" --value phone
logMessage --message "${targetCollection}" --type "Info"
// The result after the condition is executed is: [Name, Age].
Example 2: Copies the items from one list to another, based on the condition defined with the Equal to operator and the Negate parameter.
defVar --name targetCollection --type List --innertype Numeric
defVar --name valuesCollection --type List --innertype Numeric --value "[1,2,3,4,5,6,7,8,9,10]"
collectionCopyIf --target "${targetCollection}" --collection "${valuesCollection}" --operator "Equal_To" --value 5 --negate
logMessage --message "${targetCollection}" --type "Info"
// The result after the condition is executed is: [1,2,3,4,6,7,8,9,10].
Remarks
The collections inserted in both the Target Collection and Collection parameters must be of the same type.