# Class: Note

## Note(row)

This represents a Note which is a central object in the Trilium Notes project.

## Constructor

#### new Note(row)

##### Parameters:

Name | Type | Description
--- | --- | ---
`row` |  | object containing database row from "notes" table

##### Properties:

Name | Type | Description
--- | --- | ---
`noteId` | string | primary key
`type` | string | one of "text", "code", "file" or "render"
`mime` | string | MIME type, e.g. "text/html"
`title` | string | note title
`contentLength` | int | length of content
`isProtected` | boolean | true if note is protected
`isDeleted` | boolean | true if note is deleted
`isErased` | boolean | true if note's content is erased after it has been deleted
`dateCreated` | string | local date time (with offset)
`dateModified` | string | local date time (with offset)
`utcDateCreated` | string |
`utcDateModified` | string |

Source:
  - entities/note.js, line 43

### Extends

- Entity

### Methods

#### (async) addAttribute() → {Promise.<Attribute>}

Source:
  - entities/note.js, line 540

##### Returns:

Type
  Promise.<Attribute>

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

Source:
  - entities/note.js, line 868

##### Returns:

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

Type
  Promise.<Array.<Array.<string>>>

#### (async) getAttribute(type, name) → {Promise.<Attribute>}

##### Parameters:

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

Source:
  - entities/note.js, line 436

##### 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
  Promise.<Attribute>

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

##### Parameters:

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

Source:
  - entities/note.js, line 254

##### Returns:

all note's attributes, including inherited ones

Type
  Promise.<Array.<Attribute>>

#### (async) getAttributeValue(type, name) → {Promise.<(string|null)>}

##### Parameters:

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

Source:
  - entities/note.js, line 447

##### Returns:

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

Type
  Promise.<(string|null)>

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

Source:
  - entities/note.js, line 814

##### Returns:

Type
  Promise.<Array.<Branch>>

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

Source:
  - entities/note.js, line 842

##### Returns:

child branches of this note

Type
  Promise.<Array.<Branch>>

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

Source:
  - entities/note.js, line 828

##### Returns:

child notes of this note

Type
  Promise.<Array.<Note>>

#### (async) getContent() → {Promise.<*>}

Source:
  - entities/note.js, line 74

##### Returns:

Type
  Promise.<*>

#### (async) getDescendantNoteIds() → {Promise.<Array.<string>>}

Source:
  - entities/note.js, line 714

##### Returns:

return list of all descendant noteIds of this note. Returning just noteIds because number of notes can be huge. Includes also this note's noteId

Type
  Promise.<Array.<string>>

#### (async) getDescendantNotesWithAttribute(type, name, valueopt) → {Promise.<Array.<Note>>}

Finds descendant notes with given attribute name and value. Only own attributes are considered, not inherited ones

##### Parameters:

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

Source:
  - entities/note.js, line 737

##### Returns:

Type
  Promise.<Array.<Note>>

#### (async) getDescendantNotesWithLabel(name, valueopt) → {Promise.<Array.<Note>>}

Finds descendant notes with given label name and value. Only own labels are considered, not inherited ones

##### Parameters:

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

Source:
  - entities/note.js, line 775

##### Returns:

Type
  Promise.<Array.<Note>>

#### (async) getDescendantNotesWithRelation(name, valueopt) → {Promise.<Array.<Note>>}

Finds descendant notes with given relation name and value. Only own relations are considered, not inherited ones

##### Parameters:

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

Source:
  - entities/note.js, line 784

##### Returns:

Type
  Promise.<Array.<Note>>

#### (async) getJsonContent() → {Promise.<*>}

Source:
  - entities/note.js, line 109

##### Returns:

Type
  Promise.<*>

#### (async) getLabel(name) → {Promise.<(Attribute|null)>}

##### Parameters:

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

Source:
  - entities/note.js, line 591

##### Returns:

label if it exists, null otherwise

Type
  Promise.<(Attribute|null)>

#### (async) getLabelDefinitions(nameopt) → {Promise.<Array.<Attribute>>}

##### Parameters:

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

Source:
  - entities/note.js, line 293

##### Returns:

all note's label definitions, including inherited ones

Type
  Promise.<Array.<Attribute>>

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

##### Parameters:

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

Source:
  - entities/note.js, line 277

##### Returns:

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

Type
  Promise.<Array.<Attribute>>

#### (async) getLabelValue(name) → {Promise.<(string|null)>}

##### Parameters:

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

Source:
  - entities/note.js, line 615

##### Returns:

label value if label exists, null otherwise

Type
  Promise.<(string|null)>

#### (async) getLinks() → {Promise.<Array.<Attribute>>}

Get list of links coming out of this note.

Deprecated:
  - - not intended for general use
Source:
  - entities/note.js, line 801

##### Returns:

Type
  Promise.<Array.<Attribute>>

#### (async) getOwnedAttribute() → {Promise.<Attribute>}

Source:
  - entities/note.js, line 236

##### Returns:

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

Type
  Promise.<Attribute>

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

This method is a faster variant of getAttributes() which looks for only owned attributes. Use when inheritance is not needed and/or in batch/performance sensitive operations.

##### Parameters:

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

Source:
  - entities/note.js, line 212

##### Returns:

note's "owned" attributes - excluding inherited ones

Type
  Promise.<Array.<Attribute>>

#### (async) getOwnedAttributeValue(type, name) → {Promise.<(string|null)>}

##### Parameters:

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

Source:
  - entities/note.js, line 458

##### Returns:

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

Type
  Promise.<(string|null)>

#### (async) getOwnedLabel(name) → {Promise.<(Attribute|null)>}

##### Parameters:

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

Source:
  - entities/note.js, line 597

##### Returns:

label if it exists, null otherwise

Type
  Promise.<(Attribute|null)>

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

##### Parameters:

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

Source:
  - entities/note.js, line 285

##### Returns:

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

Type
  Promise.<Array.<Attribute>>

#### (async) getOwnedLabelValue(name) → {Promise.<(string|null)>}

##### Parameters:

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

Source:
  - entities/note.js, line 621

##### Returns:

label value if label exists, null otherwise

Type
  Promise.<(string|null)>

#### (async) getOwnedRelation(name) → {Promise.<(Attribute|null)>}

##### Parameters:

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

Source:
  - entities/note.js, line 609

##### Returns:

relation if it exists, null otherwise

Type
  Promise.<(Attribute|null)>

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

##### Parameters:

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

Source:
  - entities/note.js, line 309

##### Returns:

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

Type
  Promise.<Array.<Attribute>>

#### (async) getOwnedRelationTarget(name) → {Promise.<Note>|null}

##### Parameters:

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

Source:
  - entities/note.js, line 649

##### Returns:

target note of the relation or null (if target is empty or note was not found)

Type
  Promise.<Note> | null

#### (async) getOwnedRelationValue(name) → {Promise.<(string|null)>}

##### Parameters:

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

Source:
  - entities/note.js, line 633

##### Returns:

relation value if relation exists, null otherwise

Type
  Promise.<(string|null)>

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

Source:
  - entities/note.js, line 854

##### Returns:

parent notes of this note (note can have multiple parents because of cloning)

Type
  Promise.<Array.<Note>>

#### (async) getRelation(name) → {Promise.<(Attribute|null)>}

##### Parameters:

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

Source:
  - entities/note.js, line 603

##### Returns:

relation if it exists, null otherwise

Type
  Promise.<(Attribute|null)>

#### (async) getRelationDefinitions(nameopt) → {Promise.<Array.<Attribute>>}

##### Parameters:

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

Source:
  - entities/note.js, line 332

##### Returns:

all note's relation definitions including inherited ones

Type
  Promise.<Array.<Attribute>>

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

##### Parameters:

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

Source:
  - entities/note.js, line 301

##### Returns:

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

Type
  Promise.<Array.<Attribute>>

#### (async) getRelationTarget(name) → {Promise.<Note>|null}

##### Parameters:

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

Source:
  - entities/note.js, line 639

##### Returns:

target note of the relation or null (if target is empty or note was not found)

Type
  Promise.<Note> | null

#### (async) getRelationTargets(nameopt) → {Promise.<Array.<Note>>}

##### Parameters:

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

Source:
  - entities/note.js, line 317

##### Returns:

Type
  Promise.<Array.<Note>>

#### (async) getRelationValue(name) → {Promise.<(string|null)>}

##### Parameters:

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

Source:
  - entities/note.js, line 627

##### Returns:

relation value if relation exists, null otherwise

Type
  Promise.<(string|null)>

#### (async) getRevisions() → {Promise.<Array.<NoteRevision>>}

Returns note revisions of this note.

Source:
  - entities/note.js, line 791

##### Returns:

Type
  Promise.<Array.<NoteRevision>>

#### getScriptEnv() → {string}

Source:
  - entities/note.js, line 183

##### Returns:

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

Type
  string

#### (async) getTargetRelations() → {Promise.<Array.<Attribute>>}

Source:
  - entities/note.js, line 245

##### Returns:

relations targetting this specific note

Type
  Promise.<Array.<Attribute>>

#### (async) hasAttribute(type, name) → {Promise.<boolean>}

##### Parameters:

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

Source:
  - entities/note.js, line 418

##### Returns:

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

Type
  Promise.<boolean>

#### (async) hasChildren() → {boolean}

Source:
  - entities/note.js, line 821

##### Returns:

- true if note has children

Type
  boolean

#### (async) hasLabel(name) → {Promise.<boolean>}

##### Parameters:

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

Source:
  - entities/note.js, line 567

##### Returns:

true if label exists (including inherited)

Type
  Promise.<boolean>

#### (async) hasOwnedAttribute(type, name) → {Promise.<boolean>}

##### Parameters:

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

Source:
  - entities/note.js, line 427

##### Returns:

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

Type
  Promise.<boolean>

#### (async) hasOwnedLabel(name) → {Promise.<boolean>}

##### Parameters:

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

Source:
  - entities/note.js, line 573

##### Returns:

true if label exists (excluding inherited)

Type
  Promise.<boolean>

#### (async) hasOwnedRelation(name) → {Promise.<boolean>}

##### Parameters:

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

Source:
  - entities/note.js, line 585

##### Returns:

true if relation exists (excluding inherited)

Type
  Promise.<boolean>

#### (async) hasRelation(name) → {Promise.<boolean>}

##### Parameters:

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

Source:
  - entities/note.js, line 579

##### Returns:

true if relation exists (including inherited)

Type
  Promise.<boolean>

#### invalidateAttributeCache()

Clear note's attributes cache to force fresh reload for next attribute request. Cache is note instance scoped.

Source:
  - entities/note.js, line 340

#### (async) isDescendantOfNote(ancestorNoteId) → {Promise.<boolean>}

##### Parameters:

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

Source:
  - entities/note.js, line 889

##### Returns:

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

Type
  Promise.<boolean>

#### isHtml() → {boolean}

Source:
  - entities/note.js, line 173

##### Returns:

true if this note is HTML

Type
  boolean

#### isJavaScript() → {boolean}

Source:
  - entities/note.js, line 165

##### Returns:

true if this note is JavaScript (code or attachment)

Type
  boolean

#### isJson() → {boolean}

Source:
  - entities/note.js, line 160

##### Returns:

true if this note is of application/json content type

Type
  boolean

#### isRoot() → {boolean}

Source:
  - entities/note.js, line 155

##### Returns:

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

Type
  boolean

#### isStringNote() → {boolean}

Source:
  - entities/note.js, line 178

##### Returns:

true if the note has string content (not binary)

Type
  boolean

#### (async) loadAttributesToCache() → {Promise.<void>}

Source:
  - entities/note.js, line 346

##### Returns:

Type
  Promise.<void>

#### (async) removeAttribute(type, name, valueopt) → {Promise.<void>}

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:
  - entities/note.js, line 524

##### Returns:

Type
  Promise.<void>

#### (async) removeLabel(name, valueopt) → {Promise.<void>}

Remove label name-value pair, if it exists.

##### Parameters:

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

Source:
  - entities/note.js, line 700

##### Returns:

Type
  Promise.<void>

#### (async) removeRelation(name, valueopt) → {Promise.<void>}

Remove relation name-value pair, if it exists.

##### Parameters:

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

Source:
  - entities/note.js, line 709

##### Returns:

Type
  Promise.<void>

#### (async) setAttribute(type, name, valueopt) → {Promise.<void>}

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:
  - entities/note.js, line 490

##### Returns:

Type
  Promise.<void>

#### (async) setContent() → {Promise}

Source:
  - entities/note.js, line 116

##### Returns:

Type
  Promise

#### (async) setJsonContent() → {Promise}

Source:
  - entities/note.js, line 150

##### Returns:

Type
  Promise

#### (async) setLabel(name, valueopt) → {Promise.<void>}

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:
  - entities/note.js, line 682

##### Returns:

Type
  Promise.<void>

#### (async) setRelation(name, valueopt) → {Promise.<void>}

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

##### Parameters:

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

Source:
  - entities/note.js, line 691

##### Returns:

Type
  Promise.<void>

#### (async) toggleAttribute(type, enabled, name, valueopt) → {Promise.<void>}

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:
  - entities/note.js, line 473

##### Returns:

Type
  Promise.<void>

#### (async) toggleLabel(enabled, name, valueopt) → {Promise.<void>}

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:
  - entities/note.js, line 663

##### Returns:

Type
  Promise.<void>

#### (async) toggleRelation(enabled, name, valueopt) → {Promise.<void>}

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:
  - entities/note.js, line 673

##### Returns:

Type
  Promise.<void>