Multivalued Context Variables

Most of the predefined context variables are designed to hold only one value at a time. However, a few assertions can create context variables that can contain multiple values. These variables are known as multivalued context variables and they have some special handling characteristics when interpolated.
gateway83
Most of the predefined context variables are designed to hold only one value at a time. However, a few assertions can create context variables that can contain multiple values. These variables are known as multivalued context variables and they have some special handling characteristics when interpolated.
Contents:
Concatenation Options during Interpolation
When a multivalued context variable is interpolated during runtime, the default behavior is to concatenate all the values, delimited by a comma and a space. For example, the multivalued context variable
${fruits}
contains three values:
apple
pear
banana
When
${fruits}
is used inside a field in the Policy Manager, it is expanded to this value at run time:
apple, pear, banana
You can change the delimiter character (which by default is a comma). To do this, add a pipe character ("|") and a new delimiter string to the end of the context variable name, before the closing curly brace. For example, using
${fruits|!}
returns:
apple!pear!banana
You can concatenate all values without a delimiter by omitting the delimiter string:
${fruits|} = applepearbanana
To change the default delimiter, set the
template.defaultMultiValueDelimiter
Miscellaneous Cluster Properties .
Converting Multivalued Context Variables into XML
Using the concatenation delimiters, it is possible to convert a multivalued context variable into valid XML code. For example, using
${fruits|</i><i>}
returns:
apple</i><i>pear</i><i>banana
The example above is almost valid XML code, except that the code is missing the opening and closing tags. To create valid XML code, enclose the context variable within these tags:
<i>${fruits|</i><i>}</i>
. This yields the following output:
<i>apple</i><i>pear</i><i>banana</i>
To make this a well-formed XML fragment, it needs an enclosing element for the whole list. To do this, add another layer of open and close tags—these tags can be anything:
<all><i>${fruits|</i><i>}</i></all>
. The resulting well-formed XML fragment can be used in the Return Template Response to Requestor Assertion.
Indexing Options During Interpolation
To extract a single value from a multivalued context variable, use the form: "
${contextVariable[n]}
", where [n] indicates the zero-based position of the value being extracted. For example,
${fruits[0]}
returns "apple", while
${fruits[1]}
returns "pear".
If you specify a position that does not exist in the context variable, the Gateway returns an empty string and logs a warning.
(1) The interpolation described here accepts fixed values only; you cannot specify a context variable. If you need to perform a lookup using a context variable, use the Miscellaneous Cluster Properties to
true
. This cluster property also determines what happens when interpolation of a regular context variable fails (for example, if you attempt to interpolate a nonexistent variable).
Retrieving Number of Values in a Multivalued Variable
To retrieve the number of values that are stored in a multivalued context variable, add the ".length" suffix. For example, the variable "${manyValueVariable}" contains 15 values. Using the syntax
${manyValueVariable.length}
returns "15".
 
If you add the ".length" suffix to a non-multivalued context variable, no value is returned and the Gateway logs a warning message.
 
Multivalued Variables and Selectors
Some context variables can accept a suffix that modifies or reformats the value that is returned. A common use of suffixes are the Date and Time variables. For example, "${myDate.millis}" returns the millisecond timestamp for myDate. However, if myDate is a multivalued variable, you cannot use a selector to return a specific value within the array. For example, "${myDate[2].millis}" does not return the millisecond timestamp of the third date in the array. The workaround is to create a new variable to hold the value of the multivalued variable that you want to work with.