YouTrack Standalone 2017.2 Help

Set

The `Set` object stores unique values of any type, whether primitive values orobject references. The Set is used as storage for all multi-value objects inthis API: custom fields that store multiple values, issue links, issues in a project, and so on.You can access single values in the collection directly (see first(), last(), get(index)),use an iterator (see entries(), values()), or traverse with forEach(visitor)and find(predicate) methods.The workflow API is based on ECMAScript 5.1.This Set implementation mimics the functionality supported by the ES 6 Set interface.

Properties

Name

Type

Description

Read-only

added

Set

The elements that are added to a field that stores multiple values in the current transaction.Only relevant when the Set represents a multi-valued property (field) of a persistent entity.

isChanged

boolean

When the Set represents a multi-valued property (field) of a persistent entityand the field is changed in the current transaction, this property is `true`.

removed

Set

The elements that are removed from a field that stores multiple values in the current transaction.Only relevant when the Set represents a multi-valued property (field) of a persistent entity.

size

number

The number of elements in a Set.Use thoughtfully, as the calculation for large collections (like `project.issues`) may be resource consumptive.

Methods

 

add

add(element)

Add an element to a Set. If the specified value is already present, a duplicate value is not added.

Parameters:

Name

Type

Description

element

Object

The element to add to the Set.

 

clear

clear()

Remove all of the values from a Set.

 

delete

delete(element)

Remove an element from a Set. If the specified element is not present, nothing happens.

Parameters:

Name

Type

Description

element

Object

The element to remove from the Set.

 

entries

entries()

Get an iterator for the entries in a Set. The same as `values()`.Use an iterator when you need to traverse over entries until a specific conditionis met and modify the entries at the same time.

See also:

  • If you need to modify all of the elements in the Set, see forEach(visitor).

  • If you need to find an element that meets specific criteria, see find(predicate).

// We want to find first Critical among issue subtasks and assign it. var checkAndAssign = function(task) { if (task.fields.Priority.name === ctx.Priority.Critical.name) { task.fields.Assignee = ctx.currentUser; return true; } return false; }; var iter = issue.links['parent for'].entries(); var v = iter.next(); while (!v.done && !checkAndAssign(v.value)) { v = iter.next(); }

Returns:

Type

Description

Iterator.<Object>

An iterator for the collection of values.

 

find

find(predicate)

Find the first element in a Set for which a predicate function returns `true`.

issue.tags.find(function(tag) { return tag.name === 'release'; });

Parameters:

Name

Type

Description

predicate

function

A function with one argument that returnseither true or false for a given value in the Set.

Returns:

Type

Description

Object

The first value that returns `true` for the predicate function or null.

 

first

first()

Find the first object in a collection based on the order in which the elements were added to the Set.

Returns:

Type

Description

Object

The first object in a collection or null if the collection is empty.

 

forEach

forEach(visitor)

Apply a visitor function to each member of a collection.

issue.links['parent for'].forEach(function(child) { child.fields.Priority = issue.fields.Priority; });

Parameters:

Name

Type

Description

visitor

function

The function to be applied to each member of the collection.

 

get

get(index)

Find an element with a specific index position in a Set.

Parameters:

Name

Type

Description

index

number

The ordinal index of the element to be returned from the Set.

Returns:

Type

Description

Object

An object at index position in a Set, or nullif the Set contains fewer than (index + 1) elements.

 

has

has(element)

Checks a Set object to determine whether the specified element is present in the collection or not.

Parameters:

Name

Type

Description

element

Object

The element to locate in the Set.

Returns:

Type

Description

boolean

If the element is found, returns `true`, otherwise, `false`.

 

isEmpty

isEmpty()

Checks a Set object to determine whether it is empty.

Returns:

Type

Description

boolean

If the Set is empty, returns `true`, otherwise, `false`.

 

isNotEmpty

isNotEmpty()

Checks a Set object to determine whether it is not empty.

Returns:

Type

Description

boolean

If the Set is not empty, returns `true`, otherwise, `false`.

 

last

last()

Find the last object in a collection based on the order in which the elements were added to the Set.

Returns:

Type

Description

Object

The last object in a collection or null if collection is empty.

 

values

values()

Get an iterator for the entries in a Set. The same as `entries()`.

See also:

  • For details, see entries().

Returns:

Type

Description

Iterator.<Object>

An iterator for the collection of values.

 

Last modified: 7 March 2019