# JSDoc: Class: FrontendScriptApi

# Class: FrontendScriptApi

## FrontendScriptApi

Source:
  - services/frontend_script_api.js, line 14

### Members

#### currentNote

##### Properties:

Name | Type | Description
--- | --- | ---
`note` | object | where script is currently executing

Source:
  - services/frontend_script_api.js, line 20

#### originEntity

##### Properties:

Name | Type | Description
--- | --- | ---
`entity` | object | null | whose event triggered this execution

Source:
  - services/frontend_script_api.js, line 22

#### startNote

##### Properties:

Name | Type | Description
--- | --- | ---
`note` | object | where script started executing

Source:
  - services/frontend_script_api.js, line 18

### Methods

#### activateNewNote(notePath) → {Promise.<void>}

Activates newly created note. Compared to this.activateNote() also refreshes tree.

##### Parameters:

Name | Type | Description
--- | --- | ---
`notePath` | string | (or noteId)

Source:
  - services/frontend_script_api.js, line 39

##### Returns:

Type
  Promise.<void>

#### activateNote(notePath) → {Promise.<void>}

Activates note in the tree and in the note detail.

##### Parameters:

Name | Type | Description
--- | --- | ---
`notePath` | string | (or noteId)

Source:
  - services/frontend_script_api.js, line 31

##### Returns:

Type
  Promise.<void>

#### addButtonToToolbar(opts)

Adds new button the the plugin area.

##### Parameters:

Name | Type | Description
--- | --- | ---
`opts` | ToolbarButtonOptions |

Source:
  - services/frontend_script_api.js, line 58

#### createNoteLink(notePath, noteTitleopt)

Create note link (jQuery object) for given note.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`notePath` | string |  | (or noteId)
`noteTitle` | string | <optional> | if not present we'll use note title

Source:
  - services/frontend_script_api.js, line 193

#### formatDateISO(date) → {string}

##### Parameters:

Name | Type | Description
--- | --- | ---
`date` | Date |

Source:
  - services/frontend_script_api.js, line 153

##### Returns:

date in YYYY-MM-DD format

Type
  string

#### getInstanceName() → {string}

Instance name identifies particular Trilium instance. It can be useful for scripts if some action needs to happen on only one specific instance.

Source:
  - services/frontend_script_api.js, line 146

##### Returns:

Type
  string

#### getNotes(noteIds, silentNotFoundErroropt) → {Promise.<Array.<NoteShort>>}

Returns list of notes. If note is missing from cache, it's loaded. This is often used to bulk-fill the cache with notes which would have to be picked one by one otherwise (by e.g. createNoteLink())

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`noteIds` | Array.<string> |  |
`silentNotFoundError` | boolean | <optional> | don't report error if the note is not found

Source:
  - services/frontend_script_api.js, line 138

##### Returns:

Type
  Promise.<Array.<NoteShort>>

#### parseDate(str) → {Date}

##### Parameters:

Name | Type | Description
--- | --- | ---
`str` | string |

Source:
  - services/frontend_script_api.js, line 160

##### Returns:

parsed object

Type
  Date

#### refreshTree() → {Promise.<void>}

Refresh tree

Source:
  - services/frontend_script_api.js, line 184

##### Returns:

Type
  Promise.<void>

#### runOnServer(script, params) → {Promise.<*>}

Executes given anonymous function on the server. Internally this serializes the anonymous function into string and sends it to backend via AJAX.

##### Parameters:

Name | Type | Description
--- | --- | ---
`script` | string | script to be executed on the backend
`params` | Array.<?> | list of parameters to the anonymous function to be send to backend

Source:
  - services/frontend_script_api.js, line 106

##### Returns:

return value of the executed function on the backend

Type
  Promise.<*>

#### showError(message)

Show error message to the user.

##### Parameters:

Name | Type | Description
--- | --- | ---
`message` | string |

Source:
  - services/frontend_script_api.js, line 176

#### showMessage(message)

Show info message to the user.

##### Parameters:

Name | Type | Description
--- | --- | ---
`message` | string |

Source:
  - services/frontend_script_api.js, line 168