Set Variable: operations

Operations let you modify variables in ways that were previously only available through the use of advanced metadata. See the table below of the transformations available in the Set Variable behavior.

Available operations

OperationOperatorsDescription
AddOperand: IntegerAdd the value of an operand to the variable. The transformation could fail if either of the input values are not integers.
Base 64 EncodeApply base64 encoding to a variable.
Base 64 DecodeDecode a base64-encoded string.
Base 32 EncodeApply base32 encoding to a variable.
Base 32 DecodeDecode a base32-encoded string.
Bitwise ANDOperandPerform a bitwise-and operation on the variable and an operand. This transformation could generate an error if either of the inputs is not an integer.
Bitwise NOT*Perform a bitwise-not operation on the variable. This transformation could generate an error if the input is not an integer
Bitwise OROperandPerform a bitwise-or operation on the variable and an operand. This transformation could generate an error if either of the inputs is not an integer.
Bitwise-XOROperandPerform a bitwise-xor operation on the variable and an operand. This transformation could generate an error if either of the inputs is not an integer.
Decimal To HexConvert a decimal integer to a hexadecimal string. This transformation could generate an error if the input is not an integer.
DecryptAlgorithm: Picklist Encryption Key: String Initialization Vector: String Encryption Mode: Picklist Nonce: String Prepend Bytes: On/OffDecrypt an encrypted string.

📘

The first 8 bytes of the decrypted value are automatically deleted, as the corresponding operation adds a random 8 bytes to its result to make the result of the complete operation non-deterministic. Currently supported algorithms are 3DES, AES128, and AES256

DivideOperandDivide the variable by the value of an operand. This transformation could generate an error if either of the inputs is not an integer or if the value of the operand is zero (0).
EncryptAlgorithm: Picklist Encryption Key: String Initialization Vector: String Encryption Mode: Picklist Nonce: String Prepend Bytes: On/OffEncrypt the variable. The output is the nonce followed by the base-64 encoded encrypted input.

📘

In order to make the encryption non-deterministic, an 8-byte random string is prepended to the input before encryption. Therefore, when the value is decrypted, this 8-byte string must be removed to arrive at the true input string.

Epoch to StringFormat StringTransform a value taken to be in epoch time, int strftime format, into RFC2616 format or other user specified format. See also, string-to-epoch for the reverse transformation.
Extract ParameterParameter Name: String Separator: Character Case Sensitive: On/OffExtract a value from a list of parameters.

A use case for this is to extract query parameters without having to write a regular expression, but it can be used to look up values in any name/value pair list.

If several occurrences of the parameter exist, only the first one is returned. If the parameter is not found, the transformation fails and the variable gets a blank value. The separator between the name and the value of a parameter is always '=', but the parameter separator can be specified.

Example: Value (lookup table) = foo=123&bar=456&baz=789. If the parameter name is bar and the Separator is &, then the resulting variable value will be 456.

HashMin: Integer Max: IntegerHash the input string into an integer. This returns the string representation of (HASH(input) % (max-min+1)) + min , where HASH is an arbitrary function that hashes a string into an unsigned 32-bit integer.
Hex to DecimalConvert a hexadecimal string to a decimal integer.
JSON extractOperandExtract JSON data from the variable using the XPath expression you formed in an operand. For more details on the expression's syntax, see JSON extract expression examples.
Hex DecodeDecode a hex-encoded string.
Hex EncodeEncode input as hex-encoded string.
HMACHMAC Key: String HMAC Algorithm: PicklistProduce a base64 encoded digest value from the variable value and key.
Lower CaseConvert the string to lower case.
MD5 HashObtain the MD5 of the value provided in one of the attribute tags ( or ) or of the value of the assign:variable.value tag if none of the attribute tags is used. (This is backward-compatible with the behavior before the attribute tags existed.) If at least one parameter is provided, the md5 is performed on the parameters in the order in which they are provided. The transformation obtains the MD5 as a hexadecimal string of size 32 in uppercase.
MinusTransform the value into a negative value.
ModuloOperandReturn the remainder of division of the value with an operand. This transformation can fail if either of the input values is not an integer or if operand is zero (0).
MultiplyOperandMultiply the value of an operand with the variable. The transformation could fail if either of the input values are not integers.
Normalize Path WindowsRemove multiple slashes, self-references, and directory back-references.
Remove WhitespacesRemove all whitespace characters.
Compress WhitespaceConvert whitespace characters to spaces, then compress multiple space characters into only one.
SHA1Calculate an SHA1 hash from the value.

📘

The computed hash is in a raw binary form and may need to be further encoded to be usable.

SHA256Calculate an SHA256 hash from the value.

📘

The computed hash is in a raw binary form and may need to be further encoded to be usable.

String IndexSubstring: StringReturns the position of the first occurrence of a substring inside the input string, or -1 if it is not found. This comparison is case sensitive. This operation never fails, it simply returns -1 when the substring is not found.
String LengthReturns the string length of the input variable.
String to EpochFormat String: StringConvert a string value from strptime format, or a custom defined format, into epoch time. You can specify the format of the string-to-epoch transformation. If no value is specified, or the if is set to RFC2616, the format of the input string is interpreted as RFC2616 format. You can specify a custom format using strftime variables. See the strftime(3) man page for proper format variables: https://www.linux.com/learn/docs/man/4184-strftime3
SubstituteRegex: String Replacement: String Case Sensitive: On/Off Global Substitution: On/OffPerform a regular expression-based substitution (similar to Perl's =~ s/regex/replacement/flags). Specify the regex, replacement string and global+case-sensitive options.
SubstringStart Index: Integer End Index: IntegerExtracts a substring from the input variable/value. The start index is the position of the first character of the desired substring (0 for first character, 1 for second character, etc.). Negative values are relative to the right side of the input string. The end index is the position of the character after the end of the desired substring. -1 represents the last character of the string.

Consider this example for a string of abcdefghij:

Start Index = 0 , End Index = 1, Result =a

Start Index = 0 , End Index = 2, Result =ab

Start Index = 1 , End Index = 1, Result =<null>

Start Index = 1 , End Index = 2, Result =b

Start Index = 3 , End Index = -1, Result =defghij

Start Index = -2, End Index = -1, Result=j

SubtractOperandSubtract the value of an operand from the variable. The operation could fail if either of the input values are not integers.
TrimRemoves leading and trailing white spaces from the input.
Upper CaseConvert the input to upper case characters.
Base 64 URL DecodeThe same as Base 64 Decode, except before decoding replaces + with - and / with _. If due to the encoding there are not enough characters for the algorithm, this adds = characters at the end of the string. For more information, see: https://en.wikipedia.org/wiki/Base64#Output_padding
Base 64 URL EncodeThe same as Base 64 Encode, except after encoding this removes trailing = characters, replacing + with - and / with _.
URL DecodeURL decode the variable. All sequences of '%' followed by 2 hexadecimal characters are replaced with the corresponding ASCII value. The sequence '%%' is replaced with '%'. The sequence '%00' causes the transformation to fail, since the value of a variable is a null-terminated string and therefore cannot contain any null characters.

📘

'+' is NOT replaced with a space. Substitution of a + sign for a space is a feature of application/x-www-form-urlencoded POST bodies. It is not a feature of url-encoding. You can swap the + for a space with a separate substitution transformation.

URL EncodeExcept Chars: String Force Chars: StringURL encode the variable. All characters deemed unsafe or reserved by RFC 1738 are escaped. That is, they are replaced with '%' followed by their 2-character hexadecimal value.

Unsafe characters are:

ASCII characters between 0x00 and 0x1F ASCII characters between 0x7F and 0xFF. The following characters: < > " # % { } | \ ^ ~ [ ] ' ` and space. Reserved characters are: ; / ? : @ = &

URL Decode UnicodeURL decode the variable value, including unicode encoding. All sequences of '%' followed by 2 hexadecimal characters are replaced with the corresponding ASCII value. The sequence '%%' is replaced with '%'. The sequence '%00' causes the transformation to fail, since the value of a variable is a null-terminated string and therefore cannot contain any null characters.

📘

'+' is NOT replaced with a space. Substitution of a + sign for a space is a feature of application/x-www-form-urlencoded POST bodies. It is not a feature of url-encoding. You can swap the + for a space with a separate substitution transformation.

UTC SecondsConvert a string in ISO 8601 time format to UTC seconds.
XML DecodeXML-decode the variable value. This operates in the reverse of XML Encode. Invalid entities cause the operation to fail.
XML EncodeXML-encode the variable value. Characters <

Combining operations

To use more than one transformation on a variable, use multiple Set Variable behaviors in the rule. The order matters when setting the different transformations, and the transformations are applied in the order they appear in the rule. After the first transformation, any subsequent instance of the Set Variable behavior must have that variable selected as were the value is coming from. You can string as many transformations together as you want.

📘

Set Variable only allows one transformation per instance of the behavior. If you require multiple transformations for a variable, use multiple Set Variable behaviors.

For example, if you want to retrieve the first two characters of a variable's value, then change those two characters to uppercase. To do this you would need two instances of the Set Variable behavior; one to change the case of the value, and the other to retrieve the first two characters from that same value.

This is how you would accomplish this task:

How to

  1. Add the first instance of Set Variable.

    1. Select the variable you want to transform.

    2. Select Extract as the source of the value.

    3. Select Request Header.

    4. Enter the name of the header to take the value from.

    5. Select Upper Case transform.

  2. Add a second Set Variable behavior.

    1. Select the same variable.

    2. Create value from expression.

    3. Add the variable as the expression value.

    4. Select sub-string as your transformation.

    5. Start index of 0.

    6. Max index of 1.

JSON extract expression examples

The expression's syntax is based on XPath. While XPath is designed to query XML data, it also works for simpler JSON data structures. References to arrays yield values concatenated as a string. References to objects yield concatenated values of all the object's keys. References to multiple keys via a wildcard yields space delimited concatenated values.

Consider these examples of expressions and the values they extract:

JSON fileOperand expressionExtraction
{ "store": { "book": { "category": "reference", "author": "John Doe", "title": "Sayings of the Century", "price": 8.95 }, "bicycle": { "color": "red", "price": 19.95 } } }/store/book/authorJohn Doe
{ "store": { "book":[ { "category": "reference", "category": "fiction"} ], "bicycle": { "color": "red", "price": 19.95 } } }/*referencefictionred19.95
{ "store": { "book":[ { "category": "reference", "category": "fiction"} ], "bicycle": { "color": "red", "price": 19.95 } } }/store/book/*referencefiction
{ "store" : { "bicycle": { "color": "red", "price": 19.95 } } }/store/bicycle/colorred
{ "name": [ "value1", "value2" ] }/namevalue1value2
{ "name1":"value1", "name2":"value2"}/*value1 value2
[ "value1", "value2" ]/*value1 value2
[ true, false, null, 123 ]/*true false null 123
{"ID":null,"name":"Doe","first-name":"John","age":25,"hobbies":["reading","cinema",{"sports":["volley-ball","badminton"]}],"address":{}}/hobbiesreadingcinemavolley-ballbadminton
{"ID":null,"name":"Doe","first-name":"John","age":25,"hobbies":["reading","cinema",{"sports":["volley-ball","badminton"]}],"address":{}}/hobbies/*/sportsvolley-ballbadminton
{"Image":{"Width":800,"Height":600,"Title":"View from 15th Floor","Thumbnail":{"Url":"http://www.example.com/image/481989943","Height":125,"Width":100},"Animated":false,"IDs":[116,943,234,38793]}}/Image/Thumbnailhttp://www.example.com/image/481989943125100