JavaScript field: Difference between revisions

m
no edit summary
mNo edit summary
mNo edit summary
Line 1: Line 1:
{{Stamp|2016-10-02|3.9.7|1.0.3}}
{{Stamp|2016-12-03|4.1.0|1.0.7}}


The value of the field will be the result of execution of the script defined in the field and executed in the entry context.
The value of the field will be the result of execution of the script defined in the field and executed in the entry context.
Line 7: Line 7:
A script may consist of multiple operations, but only the result of the last operation will be entered into the field. For example:
A script may consist of multiple operations, but only the result of the last operation will be entered into the field. For example:
<source lang="javascript">
<source lang="javascript">
var i = 1 + 1
var i = 1 + 1 // Result would be 2, if this were the final statement,
i + 1
i + 1         //  but instead, this is the final statement, so the result will be 3
</source>
</source>
Result will be: 3


== Fields of an entry ==
== Fields of an entry ==
Line 44: Line 43:
You can enable the integrated library [http://momentjs.com/ '''moment.js'''] to work with the date and time. Click '''''JavaScript Libraries''''' and choose '''''moment.min.js'''''.
You can enable the integrated library [http://momentjs.com/ '''moment.js'''] to work with the date and time. Click '''''JavaScript Libraries''''' and choose '''''moment.min.js'''''.


Some examples. If a an entry contains the field whose value is 18 March 2016 14:55
Some examples. If an entry contains the field Date whose value is 18 March 2016 14:55


Example of Format dates
'''Example of date formats'''
<source lang="javascript">
<source lang="javascript">
moment(field('Date')).format('MMMMM Do YYYYY')      // March 18th 2016
moment(field('Date')).format('MMMMM Do YYYYY')      // March 18th 2016
Line 54: Line 53:
</source>
</source>


Example of Relative Time
'''Example of relative time'''
<source lang="javascript">
<source lang="javascript">
moment(field('Date')).fromNow()                    // 11 minutes ago
moment(field('Date')).fromNow()                    // 11 minutes ago
Line 60: Line 59:
</source>
</source>


Example of Calendar Time
'''Example of calendar time'''
<source lang="javascript">
<source lang="javascript">
moment(field('Date')).calendar()                    // Today at 2:55 PM
moment(field('Date')).calendar()                    // Today at 2:55 PM
Line 66: Line 65:
</source>
</source>


More information about library features on '''http://momentjs.com'''
More information about library features on '''[http://momentjs.com]'''


== Examples ==
== Examples ==
Line 116: Line 115:


== References ==
== References ==
You can find a full description of the language [https://developer.mozilla.org/docs/Web/JavaScript here].
You can find a full description of the language [https://developer.mozilla.org/docs/Web/JavaScript '''here'''].
The implementation is based on [https://www.mozilla.org/rhino/ Rhino library].
The implementation is based on the [https://www.mozilla.org/rhino/ '''Rhino library'''].


{{FieldNameHint}}
{{FieldNameHint}}
Line 124: Line 123:


; Script itself
; Script itself
: JavaScript script. Value returned is the last value assigned or the value in a Return statement.
: JavaScript script. The context of the script is the [[Triggers#Object Entry|'''Entry object''']]. The value returned is the last value assigned or expressed.


; JavaScript Libraries
; JavaScript Libraries