# Changes

,  20:49, 22 January 2017
m
no edit summary
Line 105: Line 105:
==== Example: Birthday====

==== Example: Birthday====
We have birthday field. If a person younger than 18 years we want displaying string "youth", else "adult".
+
We have a birthday field. If a person is younger than 18 years old, we want to display the string "youth", otherwise the string "adult".

<source lang="javascript">

<source lang="javascript">

var years = moment().diff(field('Birthday') , 'years' )

var years = moment().diff(field('Birthday') , 'years' )
Line 112: Line 112:
else

else

+
</source>
+
+
=== Examples of calculations on linked entries ===
+
If you have a many-to-many Link To Entry field &mdash; linking the current entry to zero or more entries in another library &mdash; and if you have an amount field in that other library, you may want to perform calculations on that field across those entries, in similar fashion to Memento aggregation functions.
+
+
==== Example: Sum of linked amounts ====
+
<source lang="javascript">
+
var amountField = "Amount";        // CHANGE Amount to your amount field name
+
+
+
+
// Loop through linked entries, creating the sum
+
for (var lex = 0, result = 0; lex < numLE; lex++)
+
+
+
result;                            // The result is the SUM
+
+
</source>
+
+
==== Example: Average of linked amounts ====
+
<source lang="javascript">
+
var amountField = "Amount";        // CHANGE Amount to your amount field name
+
+
+
+
// Loop through linked entries, creating the sum
+
for (var lex = 0, result = 0; lex < numLE; lex++)
+
+
+
if (numLE != 0)
+
result / numLE;                // The result is the AVERAGE
+
</source>
+
+
==== Example: Minimum of linked amounts ====
+
<source lang="javascript">
+
var amountField = "Amount";        // CHANGE Amount to your amount field name
+
+
+
var temp;
+
+
// Loop through linked entries, finding the MINIMUM
+
for (var lex = 0, result = 0; lex < numLE; lex++) {
+
+
if (temp < result)
+
result = temp;
+
}
+
+
result;                            // The result is the MINIMUM
+
</source>
+
+
==== Example: Maximum of linked amounts ====
+
<source lang="javascript">
+
var amountField = "Amount";        // CHANGE Amount to your amount field name
+
+
+
var temp;
+
+
// Loop through linked entries, finding the MAXIMUM
+
for (var lex = 0, result = 0; lex < numLE; lex++) {
+
+
if (temp > result)
+
result = temp;
+
}
+
+
result;                            // The result is the MAXIMUM

</source>

</source>