|
|
Contents of this GuideIntroductionThe Magma Javascript API is there to allow accession of Magma variable catalogue. It is used for Onyx and Opal configuration. SyntaxSelectors and Execution contextThe 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. ChainingMethods from this API return an object to which a method can be directly applied. This allow method calls chaining. Examples MethodsGlobal$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. $varReturns 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. logProvides 'info' level logging of messages and variable values. Examples nowReturns the current date time wrapped in a value object. Examples Get the current date time. VariablesattributeGet the variable attribute value with the given name. Examples Get the value corresponding to the 'stage' attribute: nameGet the name of the variable as a value. Examples If the scriptable context is a variable, get its name. repeatableReturns if the variable is repeatable, as a value. Examples ValuesvalueReturns the javascript value from the Value. Examples SequencesfirstReturns the first value in a value sequence. Examples lastReturns the last value in a value sequence. Examples valueAtReturns the a value at a specified index within the sequence (0-based). Examples sizeReturns the number of values within a sequence. Examples sortSorts a sequence in natural order of its values or using a custom javascript comparing function. Examples Boolean ValuesallReturns true when the value contains all specified parameters, false otherwise. Note that this method will always return false if the value is null. Examples andApplies the ternary and logic on values. If no arguments is provided, returns the value of the left operand. Examples anyReturns 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 emptyReturns true value if is operating on a sequence that contains zero values. Otherwise false value is returned. Examples isNullReturns true if the value is null. Examples notExamples orApplies the ternary or logic on values. If no arguments is provided, returns the value of the left operand. Examples gtReturns if left operand value is greater than right operand value. The operands must be either be of integer or decimal type. geReturns if left operand value is greater equal than right operand value. The operands must be either be of integer or decimal type. ltReturns if left operand value is lower than right operand value. The operands must be either be of integer or decimal type. leReturns if left operand value is lower equal than right operand value. The operands must be either be of integer or decimal type. eqReturns 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:
Examples Numeric ValuesFor Numeric operations a value of integer type is returned if both operands are of the integer type. The decimal type is returned otherwise. plusReturns result of first operand value plus second operand value. The operands must be either be of integer or decimal type.e. minusReturns result of first operand value minus second operand value. The operands must be either be of integer or decimal type. multiplyReturns result of first operand value multiply second operand value. The operands must be either be of integer or decimal type. divReturns 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. ComparisonThe 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. compareReturns the comparison result for (integer type and/or decimal type), boolean type and text type. compareNoCaseReturns the comparison result for text type, ignoring case. Date Time ValuesaddAdds days to a value of date time type. Examples afterReturns true if the date value is after the specified date value(s). Examples dayOfMonthReturns the day of month from a date as an integer starting from 1. Examples dayOfWeekReturns the day of week from a date as an integer starting from 1 (Sunday). Examples dayOfYearReturns the day of year from a date as an integer starting from 1. Examples monthReturns the month of a Date as an integer starting from 0 (January). Examples weekdayReturns a boolean value indicating whether the date denotes a weekday (between Monday and Friday inclusively). Examples weekendReturns a boolean value indicating whether the date denotes a weekend (either Sunday or Saturday). Examples weekOfMonthReturns the week of month from a date as an integer starting from 1. Examples weekOfYearReturns the week of year from a date as an integer starting from 1. Examples yearReturns the year value. Examples Text ValuesmatchesUsed to match a regular expression against a string. concatReturns the text type result of first operand concat second operand. The operands must be either be text type. replaceUsed 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 trimGets the string representation of the Value. Returns a copy of the string, with leading and trailing whitespace omitted. Onyx extensionsThe following methods only apply when executed by Onyx. onyxAllows 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 StatementsTo 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-elseswitch |
Search Opal Documentation |
Magma Javascript API
Labels:
None