https://wiki.mementodatabase.com/index.php?title=About:Scripting&feed=atom&action=historyAbout:Scripting - Revision history2024-03-29T07:49:51ZRevision history for this page on the wikiMediaWiki 1.39.2https://wiki.mementodatabase.com/index.php?title=About:Scripting&diff=4110&oldid=prevUnConnoisseur: Created page with "{{Stamp|2022-02-14|4.10.3|1.10.1}} {{BannerMenu}} = Scripting in the Memento application = == Native Memento Calculation scripting == The specifications for scripting for th..."2022-02-14T16:52:16Z<p>Created page with "{{Stamp|2022-02-14|4.10.3|1.10.1}} {{BannerMenu}} = Scripting in the Memento application = == Native Memento Calculation scripting == The specifications for scripting for th..."</p>
<p><b>New page</b></p><div>{{Stamp|2022-02-14|4.10.3|1.10.1}}<br />
{{BannerMenu}}<br />
<br />
= Scripting in the Memento application =<br />
<br />
== Native Memento Calculation scripting ==<br />
The specifications for scripting for the Calculation field type is described in '''[[Calculation field]]'''.<br />
<br />
== Scripting Memento in JavaScript ==<br />
Scripting in JavaScript is available in '''[[Spec:JavaScript field|JavaScript field]]''', '''[[Spec:Triggers|Triggers]]''', '''[[Spec:Actions|Actions]]''', and '''[[Spec:Custom Data Sources|Custom Data Sources]]'''.<br />
<br />
=== The '''[[JavaScript field]]''' type ===<br />
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|Write scripts in JavaScript for Memento#JavaScript field]] for a detailed discussing of the JavaScript field.<br />
<br />
==== Example JavaScript field usage ====<br />
* The field() function gets the value of the field from Memento.<br />
* Anything after "//" is ignored, so you can use it for comments.<br />
* For numbers, x * y means the numerical ''product'' of x times y.<br />
* x = y means for Memento to assign to x the value of y.<br />
* For numbers, x + y means the ''sum'' of x and y, while if x & y are strings of text, it means x ''concatenated'' with y.<br />
:; Item price&nbsp;&nbsp;&nbsp;&nbsp;// ''on an invoice'':field("Unit price") * field("Quantity")<br />
:; Amount for display&nbsp;&nbsp;&nbsp;&nbsp;// ''Final sum'': field("Total") + " widgets"<br />
:; Limited&nbsp;&nbsp;&nbsp;&nbsp;// ''The capped amount'': value = field("Value"); if (value <= StandardLimit) value else StandardLimit<br />
<br />
=== moment.min.js &mdash; a possibly useful wrapper for JavaScript dates & times ===<br />
See [http://momentjs.com http://momentjs.com] and its subordinate pages Guides and Docs.<br />
<br />
:; Tidbit: To get the current date, use ''moment().toDate()''. To get the current date & time, use ''moment().toDate().getTime()''.<br />
<br />
[[Category:About]] [[Category:en]]</div>UnConnoisseur