docs/Script API/classes/Backend_Script_API.BNote.html
Trilium's main entity, which can represent text note, image, code note, file attachment etc.
__flatTextCacheblobId?childrencontentAndAttachmentsAndRevisionsSizecontentAndAttachmentsSizecontentSizedateCreated?dateModified?isBeingDeletedisDecryptedisProtected?isSynced?mimenoteIdownedAttributesparentBranchesparentsrevisionCounttargetRelationstitletypeutcDateCreatedutcDateModified?
attributeCountbeccachildrenCountdateCreatedObjdateModifiedObjisArchivedisDeletedlabelCountownedAttributeCountownedLabelCountownedRelationCountownedRelationCountIncludingLinksparentCountrelationCountrelationCountIncludingLinkstargetRelationCounttargetRelationCountIncludingLinksutcDateCreatedObjutcDateModifiedObjentityNamehashedPropertiesprimaryKeyName
__validateTypeName_getContent_setContentaddAttributeaddLabeladdRelationareAllNotePathsArchivedbeforeSavingcloneToconvertToParentAttachmentdecryptdeleteNoteeraseExcessRevisionSnapshotsgenerateHashgetAllNotePathsgetAncestorNoteIdsgetAncestorsgetAttachmentByIdgetAttachmentByTitlegetAttachmentsgetAttachmentsByRolegetAttributegetAttributeCaseInsensitivegetAttributesgetAttributeValuegetBestNotePathgetBestNotePathStringgetBranchesgetChildBranchesgetChildNotesgetContentgetDescendantNoteIdsgetDistanceToAncestorgetFileNamegetFilteredChildBranchesgetFlatTextgetIcongetInheritingNotesgetJsonContentgetJsonContentSafelygetLabelgetLabelDefinitionsgetLabelsgetLabelValuegetLabelValuesgetOwnedAttributegetOwnedAttributesgetOwnedAttributeValuegetOwnedLabelgetOwnedLabelsgetOwnedLabelValuegetOwnedLabelValuesgetOwnedRelationgetOwnedRelationsgetOwnedRelationValuegetParentBranchesgetParentNotesgetPojogetPojoToSavegetRelationgetRelationDefinitionsgetRelationsgetRelationTargetgetRelationValuegetRevisionsgetScriptEnvgetSearchResultNotesgetSortedNotePathRecordsgetStrongParentBranchesgetSubtreegetSubtreeNoteIdsgetSubtreeNotesIncludingTemplatedgetTargetRelationsgetTitleOrProtectedgetUtcDateChangedhasAncestorhasAttributehasChildrenhasInheritableArchivedLabelhasLabelhasOwnedAttributehasOwnedLabelhasOwnedRelationhasRelationhasStringContentinitinvalidateSubTreeinvalidateThisCacheisContentAvailableisDescendantOfNoteisEligibleForConversionToAttachmentisFolderisHiddenCompletelyisHtmlisImageisInheritedisInHiddenSubtreeisJavaScriptisJsonisLabelTruthyisLaunchBarConfigisOptionsisRootisStringNotemarkAsDeletedmarkAsDeletedSimpleputEntityChangeremoveAttributeremoveLabelremoveRelationsavesaveAttachmentsaveRevisionsearchNoteInSubtreesearchNotesInSubtreesetAttributesetContentsetJsonContentsetLabelsetRelationsortChildrensortParentstoggleAttributetoggleLabeltoggleRelationupdateupdateFromRow
new BNote(row?: Partial<NoteRow>): BNote
__flatTextCache: null | string
OptionalblobIdblobId?: string
children: BNote[]
contentAndAttachmentsAndRevisionsSize: null | number
size of the note content, attachment contents and revision contents in bytes
contentAndAttachmentsSize: null | number
size of the note content, attachment contents in bytes
contentSize: null | number
size of the content in bytes
OptionaldateCreateddateCreated?: string
OptionaldateModifieddateModified?: string
isBeingDeleted: boolean
set during the deletion operation, before it is completed (removed from becca completely).
isDecrypted: boolean
OptionalisProtectedisProtected?: boolean
OptionalisSyncedisSynced?: boolean
mime: string
noteId: string
ownedAttributes: BAttribute[]
parentBranches: BBranch[]
parents: BNote[]
revisionCount: null | number
number of note revisions for this note
targetRelations: BAttribute[]
title: string
type:
| "canvas"
| "code"
| "search"
| "image"
| "text"
| "file"
| "noteMap"
| "launcher"
| "doc"
| "contentWidget"
| "relationMap"
| "render"
| "mermaid"
| "book"
| "webView"
| "mindMap"
| "geoMap"
utcDateCreated: string
OptionalutcDateModifiedutcDateModified?: string
get attributeCount(): number
Protectedbeccaget becca(): default
get childrenCount(): number
get dateCreatedObj(): null | Dayjs
get dateModifiedObj(): null | Dayjs
get isArchived(): boolean
get isDeleted(): boolean
get labelCount(): number
get ownedAttributeCount(): number
get ownedLabelCount(): number
get ownedRelationCount(): number
get ownedRelationCountIncludingLinks(): number
get parentCount(): number
get relationCount(): number
get relationCountIncludingLinks(): number
get targetRelationCount(): number
get targetRelationCountIncludingLinks(): number
get utcDateCreatedObj(): null | Dayjs
get utcDateModifiedObj(): null | Dayjs
StaticentityNameget entityName(): string
StatichashedPropertiesget hashedProperties(): string[]
StaticprimaryKeyNameget primaryKeyName(): string
__validateTypeName(type?: null | string, name?: null | string): void
Optionaltype: null | stringOptionalname: null | stringProtected_getContent_getContent(): string | Buffer<ArrayBufferLike>
Protected_setContent_setContent(content: string | Buffer<ArrayBufferLike>, opts?: ContentOpts): void
addAttribute(
type: AttributeType,
name: string,
value?: string,
isInheritable?: boolean,
position?: null | number,
): BAttribute
Adds a new attribute to this note. The attribute is saved and returned. See addLabel, addRelation for more specific methods.
attribute type (label / relation)
name of the attribute, not including the leading ~/#
value of the attribute - text for labels, target note ID for relations; optional.
addLabel(name: string, value?: string, isInheritable?: boolean): BAttribute
Adds a new label to this note. The label attribute is saved and returned.
name of the label, not including the leading #
text value of the label; optional
addRelation(
name: string,
targetNoteId: string,
isInheritable?: boolean,
): BAttribute
Adds a new relation to this note. The relation attribute is saved and returned.
name of the relation, not including the leading ~
areAllNotePathsArchived(): boolean
beforeSaving(): void
cloneTo(parentNoteId: string): CloneResponse
convertToParentAttachment(opts?: ConvertOpts): null | BAttachment
Some notes are eligible for conversion into an attachment of its parent, note must have these properties:
Currently, works only for image notes.
In the future, this functionality might get more generic and some of the requirements relaxed.
null if note is not eligible for conversion
decrypt(): void
deleteNote(deleteId?: null | string, taskContext?: null | TaskContext): void
(Soft) delete a note and all its descendants.
optional delete identified
eraseExcessRevisionSnapshots(): void
generateHash(isDeleted?: boolean): string
OptionalisDeleted: booleangetAllNotePaths(): string[][]
Gives all possible note paths leading to this note. Paths containing search note are ignored (could form cycles)
array of notePaths (each represented by array of noteIds constituting the particular note path)
getAncestorNoteIds(): string[]
getAncestors(): BNote[]
getAttachmentById(attachmentId: string, opts?: AttachmentOpts): BAttachment
getAttachmentByTitle(title: string): undefined | BAttachment
getAttachments(opts?: AttachmentOpts): BAttachment[]
getAttachmentsByRole(role: string): BAttachment[]
getAttribute(type: string, name: string): null | BAttribute
attribute type (label, relation, etc.)
attribute name
attribute of the given type and name. If there are more such attributes, first is returned. Returns null if there's no such attribute belonging to this note.
getAttributeCaseInsensitive(
type: string,
name: string,
value?: null | string,
): undefined | BAttribute
Optionalvalue: null | stringgetAttributes(type?: string, name?: string): BAttribute[]
Beware that the method must not create a copy of the array, but actually returns its internal array (for performance reasons)
Optionaltype: string(optional) attribute type to filter
Optionalname: string(optional) attribute name to filter
all note's attributes, including inherited ones
getAttributeValue(type: string, name: string): null | string
attribute type (label, relation, etc.)
attribute name
attribute value of given type and name or null if no such attribute exists.
getBestNotePath(hoistedNoteId?: string): string[]
Returns a note path considered to be the "best"
array of noteIds constituting the particular note path
getBestNotePathString(hoistedNoteId?: string): string
Returns a note path considered to be the "best"
serialized note path (e.g. 'root/a1h315/js725h')
getBranches(): BBranch[]
use getParentBranches() instead
getChildBranches(): BBranch[]
getChildNotes(): BNote[]
getContent(): string | Buffer<ArrayBufferLike>
Note content has quite special handling - it's not a separate entity, but a lazily loaded part of Note entity with its own sync. Reasons behind this hybrid design has been:
getDescendantNoteIds(): string[]
use getSubtreeNoteIds() instead
getDistanceToAncestor(ancestorNoteId: string): number
getFileName(): string
getFilteredChildBranches(): BBranch[]
getFlatText(): string
This is used for:
getIcon(): string
getInheritingNotes(): BNote[]
returns only notes which are templated, does not include their subtrees in effect returns notes which are influenced by note's non-inheritable attributes
getJsonContent(): any
Error in case of invalid JSON
getJsonContentSafely(): any
valid object or null if the content cannot be parsed as JSON
getLabel(name: string): null | BAttribute
label name
label if it exists, null otherwise
getLabelDefinitions(): BAttribute[]
getLabels(name?: string): BAttribute[]
Optionalname: stringlabel name to filter
all note's labels (attributes with type label), including inherited ones
getLabelValue(name: string): null | string
label name
label value if label exists, null otherwise
getLabelValues(name: string): string[]
label name to filter
all note's label values, including inherited ones
getOwnedAttribute(
type: string,
name: string,
value?: null | string,
): null | BAttribute
attribute belonging to this specific note (excludes inherited attributes)
This method can be significantly faster than the getAttribute()
getOwnedAttributes(
type?: null | string,
name?: null | string,
value?: null | string,
): BAttribute[]
Beware that the method must not create a copy of the array, but actually returns its internal array (for performance reasons)
(optional) attribute type to filter
(optional) attribute name to filter
(optional) attribute value to filter
note's "owned" attributes - excluding inherited ones
getOwnedAttributeValue(type: string, name: string): null | string
attribute type (label, relation, etc.)
attribute name
attribute value of given type and name or null if no such attribute exists.
getOwnedLabel(name: string): null | BAttribute
label name
label if it exists, null otherwise
getOwnedLabels(name: string): BAttribute[]
label name to filter
all note's labels (attributes with type label), excluding inherited ones
getOwnedLabelValue(name: string): null | string
label name
label value if label exists, null otherwise
getOwnedLabelValues(name: string): string[]
label name to filter
all note's label values, excluding inherited ones
getOwnedRelation(name: string): null | BAttribute
relation name
relation if it exists, null otherwise
getOwnedRelations(name?: null | string): BAttribute[]
Optionalname: null | stringrelation name to filter
all note's relations (attributes with type relation), excluding inherited ones
getOwnedRelationValue(name: string): null | string
relation name
relation value if relation exists, null otherwise
getParentBranches(): BBranch[]
getParentNotes(): BNote[]
getPojo(): NotePojo
getPojoToSave(): NotePojo
getRelation(name: string): null | BAttribute
relation name
relation if it exists, null otherwise
getRelationDefinitions(): BAttribute[]
getRelations(name?: string): BAttribute[]
Optionalname: stringrelation name to filter
all note's relations (attributes with type relation), including inherited ones
getRelationTarget(name: string): undefined | null | BNote
getRelationValue(name: string): null | string
relation name
relation value if relation exists, null otherwise
getRevisions(): BRevision[]
getScriptEnv(): null | "frontend" | "backend"
JS script environment - either "frontend" or "backend"
getSearchResultNotes(): BNote[]
getSortedNotePathRecords(hoistedNoteId?: string): NotePathRecord[]
getStrongParentBranches(): BBranch[]
Returns strong (as opposed to weak) parent branches. See isWeak for details.
getSubtree(
__namedParameters?: {
includeArchived?: boolean;
includeHidden?: boolean;
resolveSearch?: boolean;
},
): { notes: BNote[]; relationships: Relationship[] }
getSubtreeNoteIds(
__namedParameters?: {
includeArchived?: boolean;
includeHidden?: boolean;
resolveSearch?: boolean;
},
): string[]
includes the subtree root note as well
getSubtreeNotesIncludingTemplated(): BNote[]
getTargetRelations(): BAttribute[]
getTitleOrProtected(): string
getUtcDateChanged(): string
hasAncestor(ancestorNoteId: string): boolean
hasAttribute(type: string, name: string, value?: null | string): boolean
hasChildren(): boolean
hasInheritableArchivedLabel(): boolean
hasLabel(name: string, value?: string): boolean
label name
Optionalvalue: stringlabel value
true if label exists (including inherited)
hasOwnedAttribute(type: string, name: string, value?: string): boolean
attribute name
Optionalvalue: stringattribute value
true if note has an attribute with given type and name (excluding inherited)
hasOwnedLabel(name: string, value?: string): boolean
label name
Optionalvalue: stringlabel value
true if label exists (excluding inherited)
hasOwnedRelation(name: string, value?: string): boolean
relation name
Optionalvalue: stringrelation value
true if relation exists (excluding inherited)
hasRelation(name: string, value?: string): boolean
relation name
Optionalvalue: stringrelation value
true if relation exists (including inherited)
hasStringContent(): boolean
true if the note has string content (not binary)
init(): void
invalidateSubTree(path?: string[]): void
invalidateThisCache(): void
isContentAvailable(): boolean
isDescendantOfNote(ancestorNoteId: string): boolean
true if ancestorNoteId occurs in at least one of the note's paths
isEligibleForConversionToAttachment(opts?: ConvertOpts): boolean
isFolder(): boolean
isHiddenCompletely(): boolean
boolean - true if there's no non-hidden path, note is not cloned to the visible tree
isHtml(): boolean
true if this note is HTML
isImage(): boolean
true if this note is an image
isInherited(): boolean
isInHiddenSubtree(): boolean
isJavaScript(): boolean
true if this note is JavaScript (code or attachment)
isJson(): boolean
true if this note is of application/json content type
isLabelTruthy(name: string): boolean
label name
true if label exists (including inherited) and does not have "false" value.
isLaunchBarConfig(): boolean
isOptions(): boolean
isRoot(): boolean
true if this note is the root of the note tree. Root note has "root" noteId
isStringNote(): boolean
use hasStringContent() instead
markAsDeleted(deleteId?: null | string): void
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.
markAsDeletedSimple(): void
ProtectedputEntityChangeputEntityChange(isDeleted: boolean): void
removeAttribute(type: string, name: string, value?: string): void
Removes given attribute name-value pair if it exists.
attribute type (label, relation, etc.)
attribute name
Optionalvalue: stringattribute value (optional)
removeLabel(name: string, value?: string): void
Remove label name-value pair, if it exists.
label name
Optionalvalue: stringlabel value
removeRelation(name: string, value?: string): void
Remove the relation name-value pair, if it exists.
relation name
Optionalvalue: stringrelation value (noteId)
save(opts?: {}): this
Saves entity - executes SQL, but doesn't commit the transaction on its own
Optionalopts: {}saveAttachment(
__namedParameters: AttachmentRow,
matchBy?: undefined | "title" | "attachmentId",
): BAttachment
choose by which property we detect if to update an existing attachment. Supported values are either 'attachmentId' (default) or 'title'
saveRevision(): BRevision
searchNoteInSubtree(searchString: string): BNote
searchNotesInSubtree(searchString: string): BNote[]
setAttribute(type: AttributeType, name: string, value?: string): void
Update's given attribute's value or creates it if it doesn't exist
attribute type (label, relation, etc.)
attribute name
Optionalvalue: stringattribute value (optional)
setContent(content: string | Buffer<ArrayBufferLike>, opts?: ContentOpts): void
setJsonContent(content: {}): void
setLabel(name: string, value?: string): void
Update's given label's value or creates it if it doesn't exist
label name
Optionalvalue: stringlabel value
setRelation(name: string, value?: string): void
Update's given relation's value or creates it if it doesn't exist
relation name
Optionalvalue: stringrelation value (noteId)
sortChildren(): void
sortParents(): void
toggleAttribute(
type: AttributeType,
enabled: boolean,
name: string,
value?: string,
): void
Based on enabled, the attribute is either set or removed.
attribute type ('relation', 'label' etc.)
toggle On or Off
attribute name
Optionalvalue: stringattribute value (optional)
toggleLabel(enabled: boolean, name: string, value?: string): void
Based on enabled, label is either set or removed.
toggle On or Off
label name
Optionalvalue: stringlabel value (optional)
toggleRelation(enabled: boolean, name: string, value?: string): void
Based on enabled, relation is either set or removed.
toggle On or Off
relation name
Optionalvalue: stringrelation value (noteId)
update(__namedParameters: any): BNote
updateFromRow(row: Partial<NoteRow>): void
Member Visibility
ThemeOSLightDark
Constructors constructor Properties __flatTextCacheblobIdchildrencontentAndAttachmentsAndRevisionsSizecontentAndAttachmentsSizecontentSizedateCreateddateModifiedisBeingDeletedisDecryptedisProtectedisSyncedmimenoteIdownedAttributesparentBranchesparentsrevisionCounttargetRelationstitletypeutcDateCreatedutcDateModified Accessors attributeCountbeccachildrenCountdateCreatedObjdateModifiedObjisArchivedisDeletedlabelCountownedAttributeCountownedLabelCountownedRelationCountownedRelationCountIncludingLinksparentCountrelationCountrelationCountIncludingLinkstargetRelationCounttargetRelationCountIncludingLinksutcDateCreatedObjutcDateModifiedObjentityNamehashedPropertiesprimaryKeyName Methods __validateTypeName_getContent_setContentaddAttributeaddLabeladdRelationareAllNotePathsArchivedbeforeSavingcloneToconvertToParentAttachmentdecryptdeleteNoteeraseExcessRevisionSnapshotsgenerateHashgetAllNotePathsgetAncestorNoteIdsgetAncestorsgetAttachmentByIdgetAttachmentByTitlegetAttachmentsgetAttachmentsByRolegetAttributegetAttributeCaseInsensitivegetAttributesgetAttributeValuegetBestNotePathgetBestNotePathStringgetBranchesgetChildBranchesgetChildNotesgetContentgetDescendantNoteIdsgetDistanceToAncestorgetFileNamegetFilteredChildBranchesgetFlatTextgetIcongetInheritingNotesgetJsonContentgetJsonContentSafelygetLabelgetLabelDefinitionsgetLabelsgetLabelValuegetLabelValuesgetOwnedAttributegetOwnedAttributesgetOwnedAttributeValuegetOwnedLabelgetOwnedLabelsgetOwnedLabelValuegetOwnedLabelValuesgetOwnedRelationgetOwnedRelationsgetOwnedRelationValuegetParentBranchesgetParentNotesgetPojogetPojoToSavegetRelationgetRelationDefinitionsgetRelationsgetRelationTargetgetRelationValuegetRevisionsgetScriptEnvgetSearchResultNotesgetSortedNotePathRecordsgetStrongParentBranchesgetSubtreegetSubtreeNoteIdsgetSubtreeNotesIncludingTemplatedgetTargetRelationsgetTitleOrProtectedgetUtcDateChangedhasAncestorhasAttributehasChildrenhasInheritableArchivedLabelhasLabelhasOwnedAttributehasOwnedLabelhasOwnedRelationhasRelationhasStringContentinitinvalidateSubTreeinvalidateThisCacheisContentAvailableisDescendantOfNoteisEligibleForConversionToAttachmentisFolderisHiddenCompletelyisHtmlisImageisInheritedisInHiddenSubtreeisJavaScriptisJsonisLabelTruthyisLaunchBarConfigisOptionsisRootisStringNotemarkAsDeletedmarkAsDeletedSimpleputEntityChangeremoveAttributeremoveLabelremoveRelationsavesaveAttachmentsaveRevisionsearchNoteInSubtreesearchNotesInSubtreesetAttributesetContentsetJsonContentsetLabelsetRelationsortChildrensortParentstoggleAttributetoggleLabeltoggleRelationupdateupdateFromRow