Scripting: Difference between revisions
mNo edit summary |
mNo edit summary |
||
Line 9: | Line 9: | ||
=== The '''[[JavaScript field]]''' type === | === The '''[[JavaScript field]]''' type === | ||
Like the Memento Calculation field type that | Like the Memento Calculation field type that came before it, the JavaScript field exists to produce ("return") a value calculated with an ''expression'' or formula. JavaScript fields use a somewhat simplified form of Memento JavaScript. For instance, it assumes the current entry for its context, while in full Memento JavaScript, the script must locate & provide the entry to operate on. While it can access any field in any library the current library is linked to, it doesn't have the complexity to access any field in any entry in any library, as you can in full Memento JavaScript. See [[How:Write scripts in JavaScript for Memento#JavaScript field]] for a detailed discussing of the JavaScript field. | ||
==== Example | ==== Example JavaScript field usage ==== | ||
* The field() function gets the value of the field from Memento. | |||
* Anything after "//" is ignored, so you can use it for comments. | |||
* For numbers, x * y means the product of x times y. | |||
* For numbers, x + y means the sum of x and y, while with strings of text, it means x concatenated with y. | |||
:; Item price // on an invoice:field("Unit price") * field("Quantity") | |||
:; Amount for display // Final sum: field("Total") + " widgets" | |||
:; | :; Limited // The capped amount: value = field("Value"); if (value <= StandardLimit) value else StandardLimit | ||
=== JavaScript scripting for [[Triggers|'''Memento Triggers''']] === | === JavaScript scripting for [[Triggers|'''Memento Triggers''']] === |
Revision as of 08:01, 24 April 2021
« NOTE: THIS PAGE IS ACTIVELY UNDER DEVELOPMENT & WILL BE UPDATED DIRECTLY. Please be patient. »
Native Memento Calculation scripting
Scripting for the Calculation field type is described in Calculation field.
Scripting Memento in JavaScript
Scripting in JavaScript is available in JavaScript field and Triggers.
The JavaScript field type
Like the Memento Calculation field type that came before it, the JavaScript field exists to produce ("return") a value calculated with an expression or formula. JavaScript fields use a somewhat simplified form of Memento JavaScript. For instance, it assumes the current entry for its context, while in full Memento JavaScript, the script must locate & provide the entry to operate on. While it can access any field in any library the current library is linked to, it doesn't have the complexity to access any field in any entry in any library, as you can in full Memento JavaScript. See How:Write scripts in JavaScript for Memento#JavaScript field for a detailed discussing of the JavaScript field.
Example JavaScript field usage
- The field() function gets the value of the field from Memento.
- Anything after "//" is ignored, so you can use it for comments.
- For numbers, x * y means the product of x times y.
- For numbers, x + y means the sum of x and y, while with strings of text, it means x concatenated with y.
- Item price // on an invoice
- field("Unit price") * field("Quantity")
- Amount for display // Final sum
- field("Total") + " widgets"
- Limited // The capped amount
- value = field("Value"); if (value <= StandardLimit) value else StandardLimit
JavaScript scripting for Memento Triggers
moment.min.js — a possibly useful wrapper for JavaScript dates & times
See http://momentjs.com and its subordinate pages Guides and Docs.
- Tidbit
- To get the current date, use moment().toDate(). To get the current date & time, use moment().toDate().getTime().