Calculation field: Difference between revisions

m
no edit summary
mNo edit summary
mNo edit summary
Line 1: Line 1:
<div align="right"><small>''&laquo; as of 2016-08-25, editions Mobile 3.9.7, Desktop 1.0.3 &raquo;''</small></div>
<div align="right"><small>''&laquo; as of 2016-08-26, editions Mobile 3.9.7, Desktop 1.0.3 &raquo;''</small></div>
-----
-----
The values in Calculation fields are calculated from the expressions specified by you.<br />
The values in Calculation fields are calculated from the expressions specified by you in Memento Script, defined herein.
 
The following types of expressions are supported:
The following types of expressions are supported:
* Numeric - Expression involving numbers.
; Numeric : Expression involving numbers.
* String - Strings can also be added together, compared, etc...
; String : Strings can also be added together, compared, etc...
* Boolean - Expressions that evaluate to true (1.0) and false (0.0).
; Boolean : Expressions that evaluate to true (1.0) and false (0.0).
* Numeric and string types can not be mixed in a left / right operand pair.  
 
Numeric and string types can not be mixed in a left / right operand pair.  


== Variables ==
== Variables ==
Line 47: Line 49:
* ''String result'' is used for expressions that contain string manipulations or functions that return a string.
* ''String result'' is used for expressions that contain string manipulations or functions that return a string.


== Link to entry ==
== Link to Entry ==
Use the following syntax to get access to the values of entry fields like Link to entry:
Use the following syntax to get access to the values of entry fields like Link to Entry:
<source lang="java">
<source lang="java">
#{field_name.child_field_name}
#{field name.child field name}
</source>
</source>
where ''field_name'' – name of field like Link to the entry, ''child_field_name'' – name of one field of a related entry.
where ''field name'' – name of field like Link to the entry, ''child field name'' – name of one field of a related entry.


If a field like Link to the entry contains several links, then use index (starts from zero) to get access to them:
If a field like Link to the entry contains several links, then use index (starts from zero) to get access to them:
<source lang="java">
<source lang="java">
#{field_name@0.child_field_name}, #{field_name@1.child_field_name}, …  
#{field name@0.child field name}, #{field name@1.child field name}, …  
</source>
</source>


You can specify one of the supported aggregation functions instead of the index:
You can specify one of the supported aggregation functions instead of the index:
<source lang="java">
<source lang="java">
#{field_name@sum.child_field_name}
#{field name@sum.child field name}
</source>  
</source>
This expression returns the sum of values of field child_field_name for all entries included into field_name. In addition, the following functions are supported: avg, min, max.


Use the following syntax to get the number of entries in field field_name:
This expression returns the sum of values of field child field name for all entries included into field name. In addition, the following functions are supported: avg, min, max.
 
Use the following syntax to get the number of entries in field field name:
<source lang="java">
<source lang="java">
#{field_name@size}
#{field name@size}
</source>
</source>


Line 80: Line 83:


==== Example: Percentage ====
==== Example: Percentage ====
Entries contain fields: Count, Total<br />
Entries contain fields: Count, Total
 
We add a Calculation field Percentage by using the following expression:
We add a Calculation field Percentage by using the following expression:
<source lang="java">
<source lang="java">