Memento JavaScript Library

From Memento Database Wiki
Revision as of 07:44, 1 March 2017 by UnConnoisseur (talk | contribs) (Created page with "{Stamp|2017-02-28|4.3.0|1.1.0} Memento includes the capability for users to use JavaScript to accomplish complex tasks beyond the capabilities of the normal Memento user inte...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

{Stamp|2017-02-28|4.3.0|1.1.0}

Memento includes the capability for users to use JavaScript to accomplish complex tasks beyond the capabilities of the normal Memento user interface. Examples include JavaScript fields, Triggers, Actions, and Data Sources. The Memento JavaScript Library may be used to access Memento facilities.

To keep JavaScript fields both easy and safe for users, they may use only a portion of the library, and the nature of its use is simplified. Any limitations or differences related to JavaScript fields will be identified.

Libraries and Entries

Library Global Functions

entry()

Get the Entry object of the Event. For example, if the script is triggered by an Update Entry event, this function will return the entry being updated.
This Entry object is a clone of the actual Entry object. If the entry is saved, this object will become the actual one, but if cancel() is called, this entry clone, along with any changes the script may have performed, will be discarded.
This function is available to all Events and Phases, with the exception of Creating an entry > Opening an Entry Edit card; for this action, use the function entryDefault().
Result
Entry object — the current entry

entryDefault()

Get the Entry object containing the default field values for the entry not yet created. This feature is available specifically and only for the Event Creating an entry & Phase Opening an Entry Edit card.
Result
DefaultEntry object

lib()

Get the library of the triggering event
Result
Library object — the current library

libByName(name)

Find the library by name. Permission to use the library is required, based on security settings.
Argument
The name of the library to find
Result
Library object — the library identified by the argument name, if found. Otherwise null.


Object Library

This object provides access to library entries. You can work with the current library — the lib() — or any other library in the database — libByName(). This function provides the ability to update existing entries and create new ones.

Library Methods

entries()
Get all the entries of the library
Result
Array object containing entries, sorted by the time of their creation, from newest to oldest
find(query)
Search field values within entries in the library matching the given query. This search is similar to searching via Memento's user interface.
Argument
query — the search string
Result
Array object containing matching entries. Entries are sorted by the time of their creation, from newest to oldest.
findByKey(name)
Search all entries by the Entry Name. The library must be set for unique Entry Names.
Argument
name — the Entry Name field value
Result
Entry object, if found. Otherwise, null.
create(values)
Create a new entry in the library
Argument
values — [Object containing the field values
Result
Entry object — the new entry in the library
show()
Display the library

Library Properties

title — The name of the library


Object Entry

This object holds an entry of the current library, allowing the setting of field values

Entry Methods

set(name, value)
Set the value of the named field. Calling this method results in immediate writing of the value to the library.
Note: In the case where the field to be set is a Link To Entry field, the second argument should be the entry name of the entry to link to. If there are, in that library, multiple fields set as Entry Name, the entry name for the set() method is formed by separating the value of those fields by a comma (,) — not a comma and a space, but only a comma.
Arguments
name — name of the field
value — the value of the field
field(name)
Get the value of the named field
Argument
name — name of the field
Result
The value of the field. The type of the result depends on the type of the field.
Field Type Return Values
Field type JavaScript object Examples
Text , Hyperlink, Password, Phone, Email, Barcode, Radio buttons, Single-choice list, Calculation (string result) String "abc"
Integer, Real number, Integer values, Rating, Currency, Calculation (number result) Number 42, 42.1
Date , DateTime, Time Date
Checkbox (Boolean) Boolean true, false
Checkboxes, Multiple-choice list Array of strings ["Shirts", "Pants", "Socks"]
Image Array of strings ["file:///storage/emulated/0/DCIM/image01.png", "file:///storage/emulated/0/DCIM/image02.png"]
Link to entry Array of entries
Each array element has a method field() for access to values of fields of entries of the linked library. Example:
field("localField")[i].field("remoteField")
[e1, e2, e3, ...]
show()
Display the entry

Entry Properties

name — entry name
title — entry name
description — entry description
favorites — true, if the entry is in Favorites
deleted — true, if the record is deleted (it is in the Recycle Bin)


Object DefaultEntry

Template with default values for a new entry. This feature is available specifically and only for the Event Creating an entry & Phase Opening an Entry Edit card.

DefaultEntry Methods

set(name, value)
Set the value of the field
Arguments
name — the name of the field
value — the value of the field


Libraries Examples

See Trigger Examples#Libraries Examples.