YouTrack InCloud 2017.2 Help

Set

The Set object stores unique values of any type, whether primitive values orobject references. The Set is used as a storage for all multiple values inthis API: multiple custom fields, links, issues in a project etc.Values can be accessed directly (see first(), last(), get(index)),via iterator (see entries(), values()), or traversed with forEach(visitor)and find(predicate) methods.This Set implementation is based on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set .However, as we are using ECMAScript 5 now, our Set implementation just mimics ES 6 Set interface.Please see details below.

Properties

NameTypeDescriptionRead-only
added Set elements that were added to a multi-valued field values during the current transaction.Only relevant in case the Set represents a multi-valued property (field) of a persistent entity.
isChanged boolean `true` in case the Set represents a multi-valued property (field) of a persistent entityand the field is changed in the current transaction.
removed Set elements that were removed from a multi-valued field values during the current transaction.Only relevant in case the Set represents a multi-valued property (field) of a persistent entity.
size number number of elements in a Set; please use accurately,as for the big collections (like `project.issues`) size calculation may beresource consuming.

Methods

 

add

add(element)

Add an element to a Set. If a value is already there, a copy is not added.

Parameters:

NameTypeDescription
element Object

 

clear

clear()

Remove all values from a Set.

 

delete

delete(element)

Remove an element from a Set. If no such element is there, nothing happens.

Parameters:

NameTypeDescription
element Object

 

entries

entries()

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

See also:

  • forEach(visitor) if you need to modify all Set elements
  • find(predicate) if you need to find an element

// 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:

TypeDescription
Iterator.<Object> iterator over collection values

 

find

find(predicate)

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

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

Parameters:

NameTypeDescription
predicate function a function with one argument that returnseither true or false for a given Set value

Returns:

TypeDescription
Object first value found or null

 

first

first()

Returns:

TypeDescription
Object first object in a collection (in an order of adding),or null if collection is empty

 

forEach

forEach(visitor)

Apply a visitor function at each member of a collection.

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

Parameters:

NameTypeDescription
visitor function

 

get

get(index)

Parameters:

NameTypeDescription
index number

Returns:

TypeDescription
Object an object at index position in a Set, or nullif Set have less elements than (index + 1)

 

has

has(element)

Parameters:

NameTypeDescription
element Object

Returns:

TypeDescription
boolean `true` if element is in Set, `false` otherwise

 

isEmpty

isEmpty()

Returns:

TypeDescription
boolean `true` if Set contains no elements, `false` otherwise

 

isNotEmpty

isNotEmpty()

Returns:

TypeDescription
boolean `true` if Set contains at least one element,`false` otherwise

 

last

last()

Returns:

TypeDescription
Object last object in a collection (in an order of adding),or null if collection is empty

 

values

values()

Get an iterator over Set entries. The same as `entries()`.

See also:

  • entries() for details

Returns:

TypeDescription
Iterator.<Object> iterator over collection values

 

Last modified: 9 August 2017