# Class: Note

## Note()

Trilium's main entity which can represent text note, image, code note, file attachment etc.

## Constructor

#### new Note()

Source:
  - becca/entities/note.js, line 23

### Extends

- AbstractEntity

### Members

#### children :Array.<Note>

##### Type:

- Array.<Note>

Source:
  - becca/entities/note.js, line 94

#### contentSize :int|null

size of the content in bytes

##### Type:

- int | null

Source:
  - becca/entities/note.js, line 120

#### dateCreated :string

##### Type:

- string

Source:
  - becca/entities/note.js, line 67

#### dateModified :string

##### Type:

- string

Source:
  - becca/entities/note.js, line 69

#### flatTextCache :string|null

##### Type:

- string | null

Source:
  - becca/entities/note.js, line 83

#### isDecrypted :boolean

##### Type:

- boolean

Source:
  - becca/entities/note.js, line 78

#### isProtected :boolean

##### Type:

- boolean

Source:
  - becca/entities/note.js, line 61

#### mime :string

##### Type:

- string

Source:
  - becca/entities/note.js, line 65

#### noteId :string

##### Type:

- string

Source:
  - becca/entities/note.js, line 57

#### noteSize :int|null

size of the content and note revision contents in bytes

##### Type:

- int | null

Source:
  - becca/entities/note.js, line 125

#### ownedAttributes :Array.<Attribute>

##### Type:

- Array.<Attribute>

Source:
  - becca/entities/note.js, line 96

#### parentBranches :Array.<Branch>

##### Type:

- Array.<Branch>

Source:
  - becca/entities/note.js, line 90

#### parents :Array.<Note>

##### Type:

- Array.<Note>

Source:
  - becca/entities/note.js, line 92

#### revisionCount :int|null

number of note revisions for this note

##### Type:

- int | null

Source:
  - becca/entities/note.js, line 130

#### targetRelations :Array.<Attribute>

##### Type:

- Array.<Attribute>

Source:
  - becca/entities/note.js, line 106

#### title :string

##### Type:

- string

Source:
  - becca/entities/note.js, line 59

#### type :string

##### Type:

- string

Source:
  - becca/entities/note.js, line 63

#### utcDateCreated :string

##### Type:

- string

Source:
  - becca/entities/note.js, line 71

#### utcDateModified :string

##### Type:

- string

Source:
  - becca/entities/note.js, line 73

### Methods

#### __getInheritableAttributes() → {Array.<Attribute>}

Source:
  - becca/entities/note.js, line 407

##### Returns:

Type
  Array.<Attribute>

#### addAttribute() → {Attribute}

Source:
  - becca/entities/note.js, line 1025

##### Returns:

Type
  Attribute

#### deleteNote(deleteIdopt, taskContextopt)

(Soft) delete a note and all its descendants.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`deleteId` | string | <optional> | optional delete identified
`taskContext` | TaskContext | <optional> |

Source:
  - becca/entities/note.js, line 1137

#### getAllNotePaths() → {Array.<Array.<string>>}

Source:
  - becca/entities/note.js, line 947

##### Returns:

- array of notePaths (each represented by array of noteIds constituting the particular note path)

Type
  Array.<Array.<string>>

#### getAncestors() → {Array.<Note>}

Source:
  - becca/entities/note.js, line 867

##### Returns:

Type
  Array.<Note>

#### getAttribute(type, name) → {Attribute}

##### Parameters:

Name | Type | Description
--- | --- | ---
`type` | string | attribute type (label, relation, etc.)
`name` | string | attribute name

Source:
  - becca/entities/note.js, line 525

##### Returns:

attribute of given type and name. If there's more such attributes, first is returned. Returns null if there's no such attribute belonging to this note.

Type
  Attribute

#### getAttributes(typeopt, nameopt) → {Array.<Attribute>}

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`type` | string | <optional> | (optional) attribute type to filter
`name` | string | <optional> | (optional) attribute name to filter

Source:
  - becca/entities/note.js, line 338

##### Returns:

all note's attributes, including inherited ones

Type
  Array.<Attribute>

#### getAttributeValue(type, name) → {string|null}

##### Parameters:

Name | Type | Description
--- | --- | ---
`type` | string | attribute type (label, relation, etc.)
`name` | string | attribute name

Source:
  - becca/entities/note.js, line 536

##### Returns:

attribute value of given type and name or null if no such attribute exists.

Type
  string | null

#### getBranches() → {Array.<Branch>}

Deprecated:
  - use getParentBranches() instead
Source:
  - becca/entities/note.js, line 152

##### Returns:

Type
  Array.<Branch>

#### getChildBranches() → {Array.<Branch>}

Source:
  - becca/entities/note.js, line 172

##### Returns:

Type
  Array.<Branch>

#### getChildNotes() → {Array.<Note>}

Source:
  - becca/entities/note.js, line 162

##### Returns:

Type
  Array.<Note>

#### getContent() → {*}

Source:
  - becca/entities/note.js, line 186

##### Returns:

Type
  *

#### getContentMetadata() → {Object}

Source:
  - becca/entities/note.js, line 220

##### Returns:

Type
  Object

#### getFlatText() → {string}

This is used for: - fast searching - note similarity evaluation

Source:
  - becca/entities/note.js, line 662

##### Returns:

- returns flattened textual representation of note, prefixes and attributes

Type
  string

#### getJsonContent() → {*}

Source:
  - becca/entities/note.js, line 231

##### Returns:

Type
  *

#### getLabel(name) → {Attribute|null}

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | string | label name

Source:
  - becca/entities/note.js, line 467

##### Returns:

label if it exists, null otherwise

Type
  Attribute | null

#### getLabels(nameopt) → {Array.<Attribute>}

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`name` | string | <optional> | label name to filter

Source:
  - becca/entities/note.js, line 557

##### Returns:

all note's labels (attributes with type label), including inherited ones

Type
  Array.<Attribute>

#### getLabelValue(name) → {string|null}

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | string | label name

Source:
  - becca/entities/note.js, line 491

##### Returns:

label value if label exists, null otherwise

Type
  string | null

#### getLabelValues(nameopt) → {Array.<string>}

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`name` | string | <optional> | label name to filter

Source:
  - becca/entities/note.js, line 565

##### Returns:

all note's label values, including inherited ones

Type
  Array.<string>

#### getOwnedAttribute() → {Attribute}

Source:
  - becca/entities/note.js, line 631

##### Returns:

attribute belonging to this specific note (excludes inherited attributes) This method can be significantly faster than the getAttribute()

Type
  Attribute

#### getOwnedAttributes(typeopt, nameopt) → {Array.<Attribute>}

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`type` | string | <optional> | (optional) attribute type to filter
`name` | string | <optional> | (optional) attribute name to filter

Source:
  - becca/entities/note.js, line 606

##### Returns:

note's "owned" attributes - excluding inherited ones

Type
  Array.<Attribute>

#### getOwnedAttributeValue(type, name) → {string|null}

##### Parameters:

Name | Type | Description
--- | --- | ---
`type` | string | attribute type (label, relation, etc.)
`name` | string | attribute name

Source:
  - becca/entities/note.js, line 547

##### Returns:

attribute value of given type and name or null if no such attribute exists.

Type
  string | null

#### getOwnedLabel(name) → {Attribute|null}

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | string | label name

Source:
  - becca/entities/note.js, line 473

##### Returns:

label if it exists, null otherwise

Type
  Attribute | null

#### getOwnedLabels(nameopt) → {Array.<Attribute>}

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`name` | string | <optional> | label name to filter

Source:
  - becca/entities/note.js, line 573

##### Returns:

all note's labels (attributes with type label), excluding inherited ones

Type
  Array.<Attribute>

#### getOwnedLabelValue(name) → {string|null}

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | string | label name

Source:
  - becca/entities/note.js, line 497

##### Returns:

label value if label exists, null otherwise

Type
  string | null

#### getOwnedLabelValues(nameopt) → {Array.<string>}

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`name` | string | <optional> | label name to filter

Source:
  - becca/entities/note.js, line 581

##### Returns:

all note's label values, excluding inherited ones

Type
  Array.<string>

#### getOwnedRelation(name) → {Attribute|null}

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | string | relation name

Source:
  - becca/entities/note.js, line 485

##### Returns:

relation if it exists, null otherwise

Type
  Attribute | null

#### getOwnedRelations(nameopt) → {Array.<Attribute>}

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`name` | string | <optional> | relation name to filter

Source:
  - becca/entities/note.js, line 597

##### Returns:

all note's relations (attributes with type relation), excluding inherited ones

Type
  Array.<Attribute>

#### getOwnedRelationValue(name) → {string|null}

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | string | relation name

Source:
  - becca/entities/note.js, line 509

##### Returns:

relation value if relation exists, null otherwise

Type
  string | null

#### getParentBranches() → {Array.<Branch>}

Source:
  - becca/entities/note.js, line 144

##### Returns:

Type
  Array.<Branch>

#### getParentNotes() → {Array.<Note>}

Source:
  - becca/entities/note.js, line 157

##### Returns:

Type
  Array.<Note>

#### getRelation(name) → {Attribute|null}

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | string | relation name

Source:
  - becca/entities/note.js, line 479

##### Returns:

relation if it exists, null otherwise

Type
  Attribute | null

#### getRelations(nameopt) → {Array.<Attribute>}

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`name` | string | <optional> | relation name to filter

Source:
  - becca/entities/note.js, line 589

##### Returns:

all note's relations (attributes with type relation), including inherited ones

Type
  Array.<Attribute>

#### getRelationValue(name) → {string|null}

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | string | relation name

Source:
  - becca/entities/note.js, line 503

##### Returns:

relation value if relation exists, null otherwise

Type
  string | null

#### getScriptEnv() → {string|null}

Source:
  - becca/entities/note.js, line 317

##### Returns:

JS script environment - either "frontend" or "backend"

Type
  string | null

#### getSubtreeNoteIds() → {Array.<String>}

Source:
  - becca/entities/note.js, line 810

##### Returns:

Type
  Array.<String>

#### getSubtreeNotes() → {Array.<Note>}

Source:
  - becca/entities/note.js, line 789

##### Returns:

Type
  Array.<Note>

#### getSubtreeNotesIncludingTemplated() → {Array.<Note>}

Source:
  - becca/entities/note.js, line 758

##### Returns:

Type
  Array.<Note>

#### getTemplatedNotes() → {Array.<Note>}

Source:
  - becca/entities/note.js, line 909

##### Returns:

- returns only notes which are templated, does not include their subtrees in effect returns notes which are influenced by note's non-inheritable attributes

Type
  Array.<Note>

#### hasAncestor() → {boolean}

Source:
  - becca/entities/note.js, line 893

##### Returns:

Type
  boolean

#### hasChildren() → {boolean}

Source:
  - becca/entities/note.js, line 167

##### Returns:

Type
  boolean

#### hasLabel(name) → {boolean}

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | string | label name

Source:
  - becca/entities/note.js, line 443

##### Returns:

true if label exists (including inherited)

Type
  boolean

#### hasOwnedAttribute(type, name) → {boolean}

##### Parameters:

Name | Type | Description
--- | --- | ---
`type` | string | attribute type (label, relation, etc.)
`name` | string | attribute name

Source:
  - becca/entities/note.js, line 516

##### Returns:

true if note has an attribute with given type and name (excluding inherited)

Type
  boolean

#### hasOwnedLabel(name) → {boolean}

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | string | label name

Source:
  - becca/entities/note.js, line 449

##### Returns:

true if label exists (excluding inherited)

Type
  boolean

#### hasOwnedRelation(name) → {boolean}

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | string | relation name

Source:
  - becca/entities/note.js, line 461

##### Returns:

true if relation exists (excluding inherited)

Type
  boolean

#### hasRelation(name) → {boolean}

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | string | relation name

Source:
  - becca/entities/note.js, line 455

##### Returns:

true if relation exists (including inherited)

Type
  boolean

#### isDescendantOfNote(ancestorNoteId) → {boolean}

##### Parameters:

Name | Type | Description
--- | --- | ---
`ancestorNoteId` |  |

Source:
  - becca/entities/note.js, line 968

##### Returns:

- true if ancestorNoteId occurs in at least one of the note's paths

Type
  boolean

#### isHtml() → {boolean}

Source:
  - becca/entities/note.js, line 306

##### Returns:

true if this note is HTML

Type
  boolean

#### isJavaScript() → {boolean}

Source:
  - becca/entities/note.js, line 298

##### Returns:

true if this note is JavaScript (code or attachment)

Type
  boolean

#### isJson() → {boolean}

Source:
  - becca/entities/note.js, line 293

##### Returns:

true if this note is of application/json content type

Type
  boolean

#### isRoot() → {boolean}

Source:
  - becca/entities/note.js, line 288

##### Returns:

true if this note is the root of the note tree. Root note has "root" noteId

Type
  boolean

#### isStringNote() → {boolean}

Source:
  - becca/entities/note.js, line 312

##### Returns:

true if the note has string content (not binary)

Type
  boolean

#### markAsDeleted(deleteIdopt)

Mark the entity as (soft) deleted. It will be completely erased later. This is a low level method, for notes and branches use `note.deleteNote()` and 'branch.deleteBranch()` instead.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`deleteId` |  | <optional> | null |

Overrides:
  - AbstractEntity#markAsDeleted
Source:
  - becca/entities/abstract_entity.js, line 118

#### removeAttribute(type, name, valueopt)

Removes given attribute name-value pair if it exists.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`type` | string |  | attribute type (label, relation, etc.)
`name` | string |  | attribute name
`value` | string | <optional> | attribute value (optional)

Source:
  - becca/entities/note.js, line 1012

#### removeLabel(name, valueopt)

Remove label name-value pair, if it exists.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`name` | string |  | label name
`value` | string | <optional> | label value

Source:
  - becca/entities/note.js, line 1103

#### removeRelation(name, valueopt)

Remove relation name-value pair, if it exists.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`name` | string |  | relation name
`value` | string | <optional> | relation value (noteId)

Source:
  - becca/entities/note.js, line 1111

#### save() → {AbstractEntity}

Saves entity - executes SQL, but doesn't commit the transaction on its own

Overrides:
  - AbstractEntity#save
Source:
  - becca/entities/abstract_entity.js, line 73

##### Returns:

Type
  AbstractEntity

#### saveNoteRevision() → {NoteRevision|null}

Source:
  - becca/entities/note.js, line 1172

##### Returns:

Type
  NoteRevision | null

#### setAttribute(type, name, valueopt)

Update's given attribute's value or creates it if it doesn't exist

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`type` | string |  | attribute type (label, relation, etc.)
`name` | string |  | attribute name
`value` | string | <optional> | attribute value (optional)

Source:
  - becca/entities/note.js, line 981

#### setLabel(name, valueopt)

Update's given label's value or creates it if it doesn't exist

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`name` | string |  | label name
`value` | string | <optional> | label value

Source:
  - becca/entities/note.js, line 1087

#### setRelation(name, value)

Update's given relation's value or creates it if it doesn't exist

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | string | relation name
`value` | string | relation value (noteId)

Source:
  - becca/entities/note.js, line 1095

#### toggleAttribute(type, enabled, name, valueopt)

Based on enabled, attribute is either set or removed.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`type` | string |  | attribute type ('relation', 'label' etc.)
`enabled` | boolean |  | toggle On or Off
`name` | string |  | attribute name
`value` | string | <optional> | attribute value (optional)

Source:
  - becca/entities/note.js, line 1054

#### toggleLabel(enabled, name, valueopt)

Based on enabled, label is either set or removed.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`enabled` | boolean |  | toggle On or Off
`name` | string |  | label name
`value` | string | <optional> | label value (optional)

Source:
  - becca/entities/note.js, line 1070

#### toggleRelation(enabled, name, valueopt)

Based on enabled, relation is either set or removed.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`enabled` | boolean |  | toggle On or Off
`name` | string |  | relation name
`value` | string | <optional> | relation value (noteId)

Source:
  - becca/entities/note.js, line 1079