Scripting: Difference between revisions

1,563 bytes added ,  23 August 2023
m
mNo edit summary
 
(21 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Stamp|2016-11-04|4.0.0|1.0.6}}
{{Stamp|2023-08-12|5.0|2.0}}
 
{{BannerMenu}}
''[[This page is a stub, with some tidbits. A more complete page is forthcoming.]]''
{{PageTitle|Scripting}}


{{NoteLine| '''''THIS PAGE IS ACTIVELY UNDER DEVELOPMENT & WILL BE UPDATED DIRECTLY.''' Please be patient.''}}
== Native Memento Calculation scripting ==
== Native Memento Calculation scripting ==
Scripting for the Calculation field type is limited and is described well in '''[[Calculation field]]'''.
Scripting for the Calculation field type is described in the '''[[Calculation field]] type'''.
Similar scripting is also available in 2 of the 3 options in the '''[[Button field]] type'''.


Scripting in Memento going forward will likely to be focused in JavaScript, as in '''[[JavaScript field]]''' and '''[[Triggers]]''', so getting used to JavaScript is recommended.
== Scripting Memento in JavaScript ==
Scripting in JavaScript is available in '''[[JavaScript field]]''' and '''[[Triggers]]'''.


'''However''', one feature of native Memento scripting that does not exist (as yet) in JavaScript is the ability to refer to fields of related libraries, so if for nothing else, it is still needed for that.
=== 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.


== Scripting Memento in JavaScript ==
==== Example JavaScript field usage ====
'''[[TBD]]'''
* 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 numerical ''product'' of x times y.
* x = y means for Memento to assign to x the value of y.
* 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.
:; Item price    // ''on an invoice'':field("Unit price") * field("Quantity")
:; Amount for display    // ''Final sum'': field("Total") + " widgets"
:; Limited&nbsp;&nbsp;&nbsp;&nbsp;// ''The capped amount'': value = field("Value"); if (value <= StandardLimit) value else StandardLimit


=== The JavaScript field type ===
=== JavaScript scripting for [[Triggers|'''Memento Triggers''']] ===
'''[[TBD]]'''
'''[[TBD]]'''


=== JavaScript scripting for Memento Triggers ===
=== moment.min.js &mdash; a possibly useful wrapper for JavaScript dates & times ===
'''[[TBD]]'''
See [http://momentjs.com http://momentjs.com] and its subordinate pages Guides and Docs.


=== moment.min.js &mdash; a useful wrapper for JavaScript dates & times ===
:; Tidbit: To get the current date, use ''moment().toDate()''. To get the current date & time, use ''moment().toDate().getTime()''.
'''[[TBD]]'''
'''[[TBD]]'''


[[Category:Overview]]
[[Category:en]] [[Category:Overview]] [[Category:Sc]]