Skip to main content
Skip table of contents

Copy: Copy a list to another list, or trim a list

Tag: Copy

The Copy function adds the content of a list to another list. It can also be used to trim a list to a subset of its elements.

Detailed Description

A list can be copied partially or entirely to another list.

The target list is created if it does not exist. If it does exist before the copy, its content is not replaced but added to.

To copy an entire list, only the names of the source and target lists need to be set.

To copy a subset of a list, the WHERE parameter and a mode of comparison need to be set.

WHERE sets which parameter is to be used for the match, the comparison mode sets how the comparison is performed to select the elements to copy.

Tag Attributes

Attributes

Value Description

Source

Any string to ID the name (required)

Target

Regular action name (required)

Where

Name of parameter to use for a source list subset selection (optional)

(where comparison mode)

If the Where attribute is used, a comparison mode is required, one of:

  • Begins

  • NotBegins

  • Equals

  • NotEquals

  • Contains

  • NotContains

  • IsInString

  • IsNotInString

  • IsIn

  • IsNotIn

  • Ends

  • NotEnds

  • GreaterThan

  • GreaterOrEquals

  • LessThan

  • LessOrEquals

Unique

True / False - defaults to false

When set to True, the target list only contains one instance of each value.

  • IsIn and IsNotIn work with a colon separated array of values:

<Copy source="sourceList" target="newTargetList" where="var2" IsIn="a:b:c"/>

Any element from sourceList whose var2 attribute equals either a, b or c is selected and copied into newTargetList.

  • When using Where, elements from the source list that do not have an attribute by the name set in the Where attribute are not copied.

Example Script

CPP
<ytriaAutomation>

    <SplitIntoSetVarList ListName="sourceList" separator=":" var1="v1:v2:v3:v4" var2="42:999:chaise"/>
    <SplitIntoSetVarList ListName="targetList" separator=":" var1="v1:v5:v6:v1" var2="43:steak:oil:44"/>

	<Copy source="sourceList" target="targetList"/>
	
	<Loop list="targetList">
		<ExecuteListAction/>
	</Loop>
	
	<Copy source="targetList" target="newTargetList" where="var2" greaterThan="42"/>
	
	<Loop list="newTargetList">
		<ExecuteListAction/>
	</Loop>

</ytriaAutomation>

In this example:

  1. Two lists are created (sourceList and targetList)

  2. sourceList is entirely copied to targetList. The content of sourceList is added to the content of targetList.

  3. targetList is partially copied to a new list that does not exist yet, newTargetList. The Where attribute restricts the copy operation to elements in targetList whose values of attribute var2 have a value greater than 42.

The console output for this script:

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.