How:Write scripts in JavaScript for Memento
« Page as of 2021-03-21, editions Mobile 4.10.0, Desktop 1.9.6 »
« NOTE: THIS PAGE IS UNDER DEVELOPMENT. »
The types of Memento JavaScript scripts are:
- A trigger script, with event & phase options
- An action script, applying to the current entry or library
- Shared code for use by trigger & action scripts
- A custom data source script to guide source data to the appropriate destination fields
JavaScript field
Like the Memento Calculation field type that game before it, the JavaScript field exists to produce ("return") a value calculated with an expression, which is a formula consisting of constants, variables, operators, and possibly statements.
Sample simple expression scripts
- 123
- the value a hundred and twenty-three
- "Memento"
- the characters M e m e n t o as a string
- 2 * currentWeight
- If currentWeight is 23 lbs, then 46 lbs
- (hours * 60) + 10
- If hours is 5 and minutes is 10, then 310
Sample complex expression script
Before release 4.10.0 on the mobile edition & 1.10.0 on the desktop edition, we had to validate entered data with a script like this one:
// Validate entered value: var StdLimit = 100 // Our std for all products value = field("Value") // Fetch value of field if (value <= StdLimit) // If within limit, value // Result is the value else // Otherwise, StdLimit // Result is the std limit
Terminology
- Constant
- a value that has a string (text) value or a numeric (number) value.
- String
- "This is a string of textual characters"
- Number
- 123 or 3.14 or -28.5
- Symbol
- a name representing a constant value, like pi, x, tareWeight, or surname
- Variable
- a name representing a value that may change over time, like sum, currentValue, or orderDate
- Operator
- one or more characters that represent the value of other values that go together in some fashion to determine a result, like + for plus or - for minus or * for multiplied by or / for divided by.
- Some operators are made up of other operators used in combination, like <= for less than or equal to or && for and also.
Trigger script
TBD
Action script
TBD
TBD
Custom data source script
TBD