system-metadata module

Use the system-metadata module to access system variables.

System variables provide you a mechanism to read from or write to DataPower® facilities across transactions or domains. Access the system-metadata module with a require('system-metadata') statement.

CAUTION:
Usage of system variables can introduce unexpected problems. Use system variables 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.variable = value;
Slash or URL notation
var sysm = require('system-metadata');
sysm.setVariable('var://system/context/variable', value) ;

Where context is the name of the context, variable 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 / characters with . characters.

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

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

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

Where context is the name of the context and variable is the name of the variable.

The following methods are available to the system-metadata module.

sysm.getVariable()

Gets the value of a system variable.

Syntax
sysm.getVariable(name)
Parameters
sysm
The name of the previously defined variable for the system-metadata object.
name
The name of the system variable to access in the form of var://system/context/variable. Where context is the name of the context and variable is the name of the variable.
Guidelines
The sysm.getVariable() method returns the value of the variable or undefined, if the variable does not exist.

sysm.setVariable()

Sets the value of a system variable.

Syntax
sysm.setVariable(name,value);
Parameters
sysm
The name of the previously defined variable for the system-metadata object.
name
The name of the system variable to be set in the form of var://system/context/variable. Where context is the name of the context and variable is the name of the variable.
value
The value that is being set in the system variable.
Guidelines
The sysm.setVariable() method 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.