Memento JavaScript Library: Difference between revisions

Jump to navigation Jump to search
m
No edit summary
Tags: Mobile edit Mobile web edit
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Stamp|2018-04-07|4.4.5|1.3.5}}
{{Stamp|2021-02-26|4.9.3|1.9.6}}


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.
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 (by all except JavaScript fields).


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.
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.
Line 7: Line 7:
== Libraries and Entries ==
== Libraries and Entries ==


=== ''Library'' Global Functions ===
=== ''Library'' global functions ===


==== entry() ====
==== 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.
: Get the Entry object of the Event. For example, if the script is triggered by an Update Entry event, this method 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 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()''.
: This global 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 global function ''entryDefault()''.


:; Result: [[#Object Entry|'''''Entry''''' object]] — the current entry
:; Result: [[#Object Entry|'''''Entry''''' object]] — the current entry
Line 41: Line 41:


=== Object ''Library'' ===
=== 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.
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 global function provides the ability to update existing entries and create new ones.


==== ''Library'' Methods ====
==== ''Library'' methods ====


===== create(values) =====
===== create(values) =====
: Create a new entry in the library
: Create a new entry in the library
: '''Argument'''
: '''Argument'''
::; values: [https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object '''''Object'''''] containing the field values
::; values: [https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object '''''Object'''''] containing the field values as its properties
:; Result: [[#Object entry|'''''Entry''''' object]] — the new entry in the library
:; Result: [[#Object entry|'''''Entry''''' object]] — the new entry to create in the library


===== entries() =====
===== entries() =====
: Get all the entries of the library
: Get all the entries of the library
:; Result: Array object containing entries, sorted by the time of their creation, from newest to oldest
:; Result: Array object containing entries (Entry objects), sorted by the time of their creation, from newest to oldest


===== find(query) =====
===== find(query) =====
Line 68: Line 68:


===== findByKey(name) =====
===== findByKey(name) =====
: Search all entries by the Entry Name. The library must be set for unique Entry Names.
: Search all entries by the entry name. The library must be set for unique entry names.
: '''Argument'''
: '''Argument'''
::; name: the Entry Name field value
::; name: the Entry name field value(s)
:; Result: [[#Object Entry|'''''Entry''''' object]], if found. Otherwise, ''null''.
:; Result: an [[#Object Entry|'''''Entry''''' object]], if found. Otherwise, ''null''.


===== linksTo(entry) =====
===== linksTo(entry) =====
Line 82: Line 82:
: Display the library
: Display the library


==== ''Library'' Properties ====
==== ''Library'' properties ====
:; name: The name of the library
:; title: The name of the library
:; title: The name of the library


Line 90: Line 91:
This object holds an entry of the current library, allowing the setting of field values
This object holds an entry of the current library, allowing the setting of field values


==== ''Entry'' Methods ====
==== ''Entry'' methods ====


===== field(name) =====
===== field(name) =====
Line 109: Line 110:
: Recalculate values of entry fields.
: Recalculate values of entry fields.


===== truch() =====
===== trash() =====
: Moves an entry into the trash.
: Moves an entry into the trash.


===== untruch() =====
===== untrash() =====
: Moves an entry out of the trash.
: Moves an entry out of the trash.


Line 118: Line 119:
: Set the value of the named field. Calling this method results in immediate writing of the value to the library.
: 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.
:'''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 the 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'''
: '''Arguments'''
Line 136: Line 137:
::; entry: Entry in the field's related library identifying the link to be removed
::; entry: Entry in the field's related library identifying the link to be removed


==== ''Entry'' Properties ====
==== ''Entry'' properties ====
:; author: the id of the user who created the entry
:; author: the id of the user who created the entry
:; creationTime: date & time the entry was created
:; creationTime: date & time the entry was created
Line 151: Line 152:
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'''.
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 ====
==== ''DefaultEntry'' methods ====


===== set(name, value) =====
===== set(name, value) =====
Line 162: Line 163:


=== Library & Entry objects examples ===
=== Library & Entry objects examples ===
See '''[[Trigger Examples#Libraries Examples]]'''.
See '''[[Trigger Examples#Libraries examples]]'''.
<br/>
<br/>
-----
-----
Line 172: Line 173:
To work with the files, the library should have read/write file access.
To work with the files, the library should have read/write file access.


=== ''File'' Global Functions ===
=== ''File'' global functions ===


==== file(name) ====
==== file(name) ====
Line 187: Line 188:
This object is returned by the global function ''file()'' and provides access to the requested file. After reading or writing, the file should be closed using the method ''close()''.
This object is returned by the global function ''file()'' and provides access to the requested file. After reading or writing, the file should be closed using the method ''close()''.


==== ''File'' Methods ====
==== ''File'' methods ====


:; close(): Close the file. It can subsequently be reopened.
:; close(): Close the file. It can subsequently be reopened.
Line 210: Line 211:
:; writeLine(text): Write strings and a newline to the file stream
:; writeLine(text): Write strings and a newline to the file stream


==== ''File'' Properties ====
==== ''File'' properties ====
:; exists: true &mdash; if and only if the file exists; false otherwise
:; exists: true &mdash; if and only if the file exists; false otherwise
:; length: The length, in bytes, of the file, or 0L if the file does not exist.  
:; length: The length, in bytes, of the file, or 0L if the file does not exist.  
<br/>
<br/>


=== Files Examples ===
=== Files examples ===
See '''[[Trigger Examples#Files Examples]]'''.
See '''[[Trigger Examples#Files examples]]'''.
<br/>
<br/>
-----
-----
Line 233: Line 234:
Interface for processing HTTP requests
Interface for processing HTTP requests


==== ''Http'' Methods ====
==== ''Http'' methods ====
 
===== http() =====
: Get the Http object
<br/>


===== get(url) =====
===== get(url) =====
Line 278: Line 283:
<br/>
<br/>


==== '' Method'' ====
==== ''Method'' ====


===== header(tag) =====
===== header(tag) =====
Line 284: Line 289:
::; tag: ???
::; tag: ???


=== Http Examples ===
=== Http examples ===
See '''[[Trigger Examples#Http Examples]]'''.
See '''[[Trigger Examples#Http examples]]'''.
<br/>
<br/>
-----
-----
<br/>
<br/>


== Performing Email Functions ==
== Performing email functions ==


=== ''Email'' Global Functions ===
=== ''Email'' global functions ===


==== email() ====
==== email() ====
Line 300: Line 305:
This object provides methods related to email.
This object provides methods related to email.


==== ''Email'' Global Functions ====
==== ''Email'' global functions ====
:; send(): Send an email message based on a provided Smtp configuration object and other arguments.
:; send(): Send an email message based on a provided Smtp configuration object and other arguments.
:: '''Arguments'''
:: '''Arguments'''
Line 310: Line 315:
=== Object ''EmailConfig'' ===
=== Object ''EmailConfig'' ===


==== ''EmailConfig'' Properties ====
==== ''EmailConfig'' properties ====


:; host: The SMTP server from which to base email requests
:; host: The SMTP server from which to base email requests
Line 322: Line 327:
:; from: The email address for the email "From:" line
:; from: The email address for the email "From:" line


=== Email Example ===
=== Email example ===
Send an email message in the background
Send an email message in the background
<source lang="JavaScript">
<source lang="JavaScript">
Line 334: Line 339:
</source>
</source>


== Interaction with the System ==
== Interaction with the system ==


=== ''System'' Global Functions ===
=== ''System'' global functions ===


==== cancel() ====
==== cancel() ====
Line 347: Line 352:
==== intent(action) ====
==== intent(action) ====
: Create an information exchange object &mdash; Intent. This function can send a request for action to another application.
: Create an information exchange object &mdash; Intent. This function can send a request for action to another application.
: This function is available only on Android.
: '''This function is available only on Android.'''
: '''Argument'''
: '''Argument'''
::; action: Line that defines standard action (eg, view, pick)
::; action: Line that defines standard action (eg, view, pick)
Line 373: Line 378:
This object contains information about the system.
This object contains information about the system.


==== ''System'' Global Functions ====
==== ''System'' global functions ====
:; exit(): End script execution
:; exit(): End script execution


==== ''System'' Properties ====
==== ''System'' properties ====
:; os: Name of the operating system executing the script
:; os: Name of the operating system executing the script
<br/>
<br/>
Line 383: Line 388:
Information exchange object. This object is created by using the global function ''intent()''.
Information exchange object. This object is created by using the global function ''intent()''.


==== ''Intent'' Methods ====
==== ''Intent'' methods ====


===== data(uri) =====
===== data(uri) =====
Line 411: Line 416:
<br/>
<br/>


=== System Examples ===
=== System examples ===
See '''[[Trigger Examples#System Examples]]'''.
See '''[[Trigger Examples#System examples]]'''.
<br/>
<br/>
-----
-----
Line 425: Line 430:
If the Contact field contains multiple contacts, use ''hasNext'' and ''next'' to retrieve them.
If the Contact field contains multiple contacts, use ''hasNext'' and ''next'' to retrieve them.


==== JSContact Methods ====
==== JSContact methods ====


:; call(): If the device is a phone, calls the primary phone number of this contact
:; call(): If the device is a phone, calls the primary phone number of this contact
Line 435: Line 440:
:; show(): Opens the Contacts app for this contact
:; show(): Opens the Contacts app for this contact


==== JSContact Properties ====
==== JSContact properties ====


:; email: The primary email address of this contact
:; email: The primary email address of this contact
Line 457: Line 462:
If the Location field contains multiple locations, use ''hasNext'' and ''next'' to retrieve them.
If the Location field contains multiple locations, use ''hasNext'' and ''next'' to retrieve them.


==== JSGeolocation Properties ====
==== JSGeolocation properties ====


:; address: Address for this Location
:; address: Address for this Location
Line 471: Line 476:
<br/>
<br/>


=== Built-in Objects Examples ===
=== Built-in Objects examples ===
See '''[[Trigger Examples#Built-in Objects Examples]]'''.
See '''[[Tips:Trigger Examples#Examples of built-in object use|Examples of built-in object use]]'''.
<br/>
<br/>
-----
-----
Line 478: Line 483:


== See also ==
== See also ==
; [[Script Actions]]: Memento Actions
; [[Actions]]: Memento Actions
; [[Script Data Sources]]: Memento Data Sources
; [[Data Sources]]: Memento Data Sources
; [[Triggers]]: Memento Triggers
; [[Triggers]]: Memento Triggers
; [[Trigger Examples]]: Examples of Memento Triggers
; [[Trigger Examples]]: Examples of Memento Triggers
Line 489: Line 494:
-----
-----
<br/>
<br/>
[[Category:Spec]]
 
[[Category:en]] [[Category:Spec]]

Navigation menu