In all of the sections above, the transform option in the setVariable behavior is set to NONE, which leaves the value unchanged after assigning it. transform supports a large set of functions that in effect offers an embedded programming language. It allows you to:
- do basic arithmetic
- perform bitwise operations
- convert case
- locate and generate substrings
- make regular expression substitutions
- perform many conversions and encodings
See the setVariable behavior for comprehensive details.
To modify a value within any setVariable behavior, set its transform function along with any necessary dependencies. Each behavior can only transform its value once, so to transform a value more than once you need to form a chain of setVariable behaviors. Each subsequent behavior needs to reassign the transformed value back to itself, then perform an additional transformation.
This simple example modifies a LANG user variable, assigning it the value of the request's Accept-Language header. The initial behavior performs a SUBSTRING transform to limit the string to the initial two-letter code. The second behavior reassigns {{user.PMUSER_LANG}} back into LANG, then runs the UPPER transform to convert to uppercase.
{
"name": "setVariable",
"options": {
"variableName": "PMUSER_LANG",
"valueSource": "EXTRACT",
"extractLocation": "CLIENT_REQUEST_HEADER",
"headerName": "Accept-Language",
"transform": "SUBSTRING",
"startIndex": "1",
"endIndex": "2"
}
},
{
"name": "setVariable",
"options": {
"variableName": "PMUSER_LANG",
"valueSource": "EXPRESSION",
"variableValue": "{{user.PMUSER_LANG}}",
"transform": "UPPER"
}
}
For more details on how to use variables within the Property Manager portal, see Variables.
