Magma Javascript API

Skip to end of metadata
Go to start of metadata

Contents of this Guide


Introduction

The Magma Javascript API is there to allow accession of Magma variable catalogue. It is used for Onyx and Opal configuration.

Syntax

Selectors and Execution context

The API offers a simple way to access to variables and variable value for a value set, based on Magma naming schema. A javascript is always defined within a context that defines implicitly the object to which the selection is applied.

See selectors description: $ and $var.

Chaining

Methods from this API return an object to which a method can be directly applied. This allow method calls chaining.

Examples

Methods

Global

$

The current object is a value set. $ will access to a variable value within this value set.

Examples

Returns the value for current value set and the named variable DO_YOU_SMOKE.

$var

Returns the variable object at the given name. The name resolution is done given an execution context.

Examples

Get the variable with name DO_YOU_SMOKE.

log

Provides 'info' level logging of messages and variable values.

Examples

now

Returns the current date time wrapped in a value object.

Examples

Get the current date time.

Variables

attribute

Get the variable attribute value with the given name.

Examples

Get the value corresponding to the 'stage' attribute:

name

Get the name of the variable as a value.

Examples

If the scriptable context is a variable, get its name.

repeatable

Returns if the variable is repeatable, as a value.

Examples

Values

value

Returns the javascript value from the Value.

Examples

Sequences

first

Returns the first value in a value sequence.

Examples

last

Returns the last value in a value sequence.

Examples

valueAt

Returns the a value at a specified index within the sequence (0-based).

Examples

size

Returns the number of values within a sequence.

Examples

sort

Sorts a sequence in natural order of its values or using a custom javascript comparing function.

Examples

Boolean Values

all

Returns true when the value contains all specified parameters, false otherwise. Note that this method will always return false if the value is null.

Examples

and

Applies the ternary and logic on values. If no arguments is provided, returns the value of the left operand.

Examples

any

Returns true value when the value is equal to any of the parameter, false otherwise. Note that this method will always return false value if the value is null.

Examples

empty

Returns true value if is operating on a sequence that contains zero values. Otherwise false value is returned.

Examples

isNull

Returns true if the value is null.

Examples

not

Examples

or

Applies the ternary or logic on values. If no arguments is provided, returns the value of the left operand.

Examples

gt

Returns if left operand value is greater than right operand value. The operands must be either be of integer or decimal type.

ge

Returns if left operand value is greater equal than right operand value. The operands must be either be of integer or decimal type.

lt

Returns if left operand value is lower than right operand value. The operands must be either be of integer or decimal type.

le

Returns if left operand value is lower equal than right operand value. The operands must be either be of integer or decimal type.

eq

Returns if left operand value is equal to right operand value. If either parameters are null, then false is returned. The operands must be either be both of:

  • integer or decimal type.
  • boolean type.
  • text type.

Examples

Numeric Values

For Numeric operations a value of integer type is returned if both operands are of the integer type. The decimal type is returned otherwise.

plus

Returns result of first operand value plus second operand value. The operands must be either be of integer or decimal type.e.

minus

Returns result of first operand value minus second operand value. The operands must be either be of integer or decimal type.

multiply

Returns result of first operand value multiply second operand value. The operands must be either be of integer or decimal type.

div

Returns result of first operand value divided by second operand value. The operands must be either be of integer or decimal type. The result of the div operations is always of decimal type.

Comparison

The returned type is always of integer type. A value of 0 indicates that the two operands are equal. A value greater than 0 indicates that the first operand is greater than the second. A value less than 0 indicates that the first operand is less than the second operand.

compare

Returns the comparison result for (integer type and/or decimal type), boolean type and text type.

compareNoCase

Returns the comparison result for text type, ignoring case.

Date Time Values

add

Adds days to a value of date time type.

Examples

after

Returns true if the date value is after the specified date value(s).

Examples

dayOfMonth

Returns the day of month from a date as an integer starting from 1.

Examples

dayOfWeek

Returns the day of week from a date as an integer starting from 1 (Sunday).

Examples

dayOfYear

Returns the day of year from a date as an integer starting from 1.

Examples

month

Returns the month of a Date as an integer starting from 0 (January).

Examples

weekday

Returns a boolean value indicating whether the date denotes a weekday (between Monday and Friday inclusively).

Examples

weekend

Returns a boolean value indicating whether the date denotes a weekend (either Sunday or Saturday).

Examples

weekOfMonth

Returns the week of month from a date as an integer starting from 1.

Examples

weekOfYear

Returns the week of year from a date as an integer starting from 1.

Examples

year

Returns the year value.

Examples

Text Values

matches

Used to match a regular expression against a string.

concat

Returns the text type result of first operand concat second operand. The operands must be either be text type.

replace

Used to find a match between a regular expression and a string, and to replace the matched substring with a new substring.

See javascript replace.

Examples

trim

Gets the string representation of the Value. Returns a copy of the string, with leading and trailing whitespace omitted.

Onyx extensions

The following methods only apply when executed by Onyx.

onyx

Allows access to the onyx configuration variables as defined in the onyx-config.properties file and to the lastExportDate.

Examples

Each the of the following statements return the Value for the named Onyx property.

Using Selection Statements

To use JavaScript selection statements such as if-else and switch first convert Magma ScriptableValues to native JavaScript values using the .value() method. Here are some examples:

if-else
switch
Search Opal Documentation
Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.