Click or drag to resize
Set data type
Print this page

The data type Set<> represents a typed and unordered list of unique items.

Usage

When creating or updating a set in TDE, you can either provide the full set or provide individual items that you can use to build the set.

Note Note

When you update a set using a template, the full set is overwritten.

The examples below demonstrate how to work with sets in TDE templates. The examples use the Teams column from the Driver table. The Teams set contains a list of IDs for the teams to which a driver belongs and has the data type Set<Id>.

To create or update a full set, use the following syntax:

Create or Update template
[Output]
Id = Input.Id
Teams = Input.Teams

An input file for the template above should contain a set of ID values for the Teams column:

CSV
Id,Teams
29320,"12570,12348,12150"

To create or update a set with individual input values, use the following syntax:

Create or Update template
[Output]
Id = Input.Id
Teams = [ Input.Team1, Input.Team2 ]

An input file for this template should contain individual ID values for Team1 and Team2:

CSV
Id,Team1,Team2
29320,32479,83341

To retrieve a set, use the following syntax:

Retrieve template
[Output]
Id = Input.Id
Teams = Input.Teams

In the example XML response below, the full Teams set is returned:

XML
<?xml version="1.0" encoding="utf-8"?>
<RetrieveDriverTeamsAndTags>
    <TableEntry Id="29320" Teams="32479,83341" />
</RetrieveDriverTeamsAndTags>
JavaScript conversion

When you use the optional [Script] section to insert your own JavaScript functions, Set<> maps to JavaScript Array, with JavaScript native array assignment.

Caution note Caution

Currently, Set<> JavaScript conversion is only supported within Retrieve templates.

Creation
JavaScript
var mySet = [x,y,z];
var myEmptySet = [];
Methods

These are the native JavaScript methods for Array objects:

  • concat() — Joins two or more arrays, and returns a copy of the joined arrays

  • indexOf() — Search the array for an element and returns its position

  • join() — Joins all elements of an array into a string

  • lastIndexOf() — Search the array for an element, starting at the end, and returns its position

  • pop() — Removes the last element of an array, and returns that element

  • push() — Adds new elements to the end of an array, and returns the new length

  • reverse() — Reverses the order of the elements in an array

  • shift() — Removes the first element of an array, and returns that element

  • slice() — Selects a part of an array, and returns the new array

  • sort() — Sorts the elements of an array

  • splice() — Adds/Removes elements from an array

  • toString() — Converts an array to a string, and returns the result

  • unshift() — Adds new elements to the beginning of an array, and returns the new length

  • valueOf() — Returns the primitive value of an array