Triggers: Difference between revisions

Jump to navigation Jump to search
4,894 bytes removed ,  1 March 2017
m
no edit summary
mNo edit summary
mNo edit summary
Line 170: Line 170:
:; No implicit context: There is no implicit context for the trigger script, as there is, for instance, in a JavaScript field. Instead, there are global functions, such as lib() and entry() that must be used to set up context for the script.
:; No implicit context: There is no implicit context for the trigger script, as there is, for instance, in a JavaScript field. Instead, there are global functions, such as lib() and entry() that must be used to set up context for the script.
:; Entry objects are clones: The Entry object associated with the Event (the one that entry() gives you) is a clone of the actual entry object. If changes are made to this object, they will be saved if the script returns normally. However, if the script calls cancel(), this clone will be discarded upon return from the script, along with any changes that have been made.
:; Entry objects are clones: The Entry object associated with the Event (the one that entry() gives you) is a clone of the actual entry object. If changes are made to this object, they will be saved if the script returns normally. However, if the script calls cancel(), this clone will be discarded upon return from the script, along with any changes that have been made.
-----
<br/>
== 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''' &gt; '''Opening an Entry Edit card'''; for this action, use the function ''entryDefault()''.
:; Result: [[#Object Entry|'''''Entry''''' object]] &mdash; 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: [[#Object DefaultEntry|'''''DefaultEntry''''' object]]
==== lib() ====
: Get the library of the triggering event
:; Result: [[#Object Library|'''''Library''''' object]] &mdash; 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: [[#Object Library|'''''Library''''' object]] &mdash; the library identified by the argument ''name'', if found. Otherwise ''null''.
<br/>
=== Object ''Library'' ===
This object provides access to library entries. You can work with the current library &mdash; the ''lib()'' &mdash; or any other library in the database &mdash; ''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''' &mdash; 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''' &mdash; the Entry Name field value
:; Result: [[#Object Entry|'''''Entry''''' object]], if found. Otherwise, ''null''.
===== create(values) =====
: Create a new entry in the library
:; Argument: '''values''' &mdash; [https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object '''''Object'''''] containing the field values
:; Result: [[#Object entry|'''''Entry''''' object]] &mdash; the new entry in the library
===== show() =====
: Display the library
==== ''Library'' Properties ====
: '''title''' &mdash; The name of the library
<br/>
=== 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 (,) &mdash; not a comma and a space, but only a comma.
:; Arguments
:: '''name''' &mdash; name of the field
:: '''value''' &mdash; the value of the field
===== field(name) =====
: Get the value of the named field
:; Argument: '''name''' &mdash; name of the field
:; Result: The value of the field. The type of the result depends on the type of the field.
::{{FieldTypeReturnValues}}
===== show() =====
: Display the entry
==== ''Entry'' Properties ====
: '''name''' &mdash; entry name
: '''title''' &mdash; entry name
: '''description''' &mdash; entry description
: '''favorites''' &mdash; true, if the entry is in Favorites
: '''deleted''' &mdash; true, if the record is deleted (it is in the Recycle Bin)
<br/>
=== 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''' &mdash; the name of the field
:: '''value''' &mdash; the value of the field
<br/>
=== Libraries Examples ===
See '''[[Trigger Examples#Libraries Examples]]'''.
<br/>
-----
-----
<br/>
<br/>

Navigation menu