system-metadata module

Use the system-metadata module to access system variables.

System variables provide you a mechanism for reading or writing DataPower® facilities across transactions or domains. Access this module with a require('system-metadata') statement.

CAUTION:
Usage of system variables could introduce unexpected problems. It is highly recommended that such usage be done only when directed by IBM support.
You can create or write system variables in dotted or slash notation.
Dotted notation
var sysm = require('system-metadata');
sysm.ContextName.VariableName = value;
Slash, or URL, notation
var sysm = require('system-metadata');
sysm.setVariable('var://system/ContextName/VariableName', value) ;
Where ContextName is the name of the context, VariableName is the name of the variable, and value is the value for the variable.

The preferred and simpler approach is to use dotted notation. In dotted notation, the variable name must be a single-word string of alphanumeric characters. If you have the URL of a system variable, you can derive the dotted notation by taking the path of the variable after the system identifier and replace / (slash) characters with . (period) characters.

To read a system variable, you can specify the dotted notation variable name or can use the getVariable() method.
var sysm = require('system-metadata');

// read the value of VariableName as a string using dotted notation
var varval = sysm.ContextName.VariableName;

// read the value of VariableName as a string using the URL or slash notation
var varval = sysm.getVariable('var://system/ContextName/VariableName');
Where ContextName is the name of the context and VariableName is the name of the variable.

system-metadata methods

Methods that are available to the system-metadata module.


getVariable()

Gets the value of a system variable. Returns the value of the variable or is undefined, if the variable does not exist.

Syntax

sysm.getVariable(name)
sysmThe name of the previously defined variable for the system metadata object.
nameThe name of the system variable to access. It must be in the form of var://system/ContextName/VariableName, where ContextName is the name of the context and VariableName is the name of the variable.

setVariable()

Sets the value of a system variable. Creates a system variable if the specified system variable does not exist. An error occurs if the value is an incorrect data type. The value can be a JavaScript primitive value or a JavaScript Object such as XML DOM Node or NodeList. However, binary data such as a Buffer or Buffers is not supported.

Syntax

sysm.setVariable(name, value);
sysmThe name of the previously defined variable for the system metadata object.
nameThe name of the system variable to be set. It must be in the form of var://system/ContextName/VariableName, where ContextName is the name of the context and VariableName is the name of the variable.
valueThe value that is being set in the system variable.