The following global functions are available for components that use JavaScript:
It is not possible to set properties on the prototypes of standard JavaScript objects. For example, String.prototype.myCustomFunction = function() {return 0;}
results in an error.
General Functions
Function |
Description |
---|---|
generateUuid() |
Used to generate a type4 UUID: var uuid = generateUuid(); |
dateChangeFormat(string dateTimeString, |
Transforms date-time formats. It takes three parameters:
The following code excerpt illustrates the conversion of return (dateChangeFormat('2012/01/02', 'YYYY/MM/dd', 'dd/MM/YYYY')); Invalid formats display errors in the stack trace:
When invoked on the engine, the |
JavaScript Counters
The following functions provide the ability to manage general-purpose JavaScript counters:
Function |
Description |
---|---|
|
Retrieves the current value of the global counter with the specified name. The value is always returned as an integer, and the counter is created with an initial value of zero if it does not currently exist. |
|
Sets the global counter with the specified name to have the value provided. If no counter with the given name exists, one will be created. |
|
Increments the global counter with the specified name by the value provided and then returns the new value. This is the safest way to use counters as it will atomically retrieve the current value, increment it, set the new value, and return it. If the |
The following example illustrates how the incCounter()
method can be used to generate new globally unique IDs. The first time this script is executed, if the MyUID
counter does not exist, it will be created with value 0
. As this is then incremented by 1
, as specified in the second argument, the counter's initial value is 1.
The ID is then set as a property on the message.
for (var i = 0; i < input.length; i++) { var next = output.append(input[i]); // Increment global counter to get new unique ID var myUniqueID = incCounter("MyUID", 1); // Set the new ID as a property on the message next.setProperty("UniqueID", myUniqueID); }
Rhapsody Variables
The following functions provide the ability to manage Rhapsody variables:
Function |
Description |
---|---|
|
Returns the value of the Rhapsody variable with the given name. For example, |
|
Takes a string which may include coded references to Rhapsody variables and returns a string in which the coded variable references have been substituted with the value of the referenced variables. If the variable has not been defined then this function will remove the coded variables reference from the string. To reference Rhapsody variables, use the following syntax: The optional |
|
Takes a string which may include coded references to Rhapsody variables and returns a string in which the coded variable references have been substituted with the value of the referenced variables. If the variable has not been defined then this function will throw an exception. To reference Rhapsody variables, use the following syntax: The optional |
Encrypted Rhapsody Variables
Encrypted Rhapsody variables are frequently used to store passwords for external systems. In some cases these passwords can be provided dynamically using Rhapsody message properties, thus allowing a single instance of the relevant communication point type to communicate with numerous external systems that use different credentials. However, retrieving the passwords and storing them in a message property means that they are subsequently visible in the Management Console to a user with permissions to view message properties.
In order to limit the need for storing passwords in message properties, the following Rhapsody communication points can use the password directly in its obfuscated form:
The obfuscated password form can be used by setting the decryptVariable
parameter to false when retrieving the password using one of the JavaScript variable functions: getVariable
, substituteVariables()
, and substituteExistingVariables()
. Alternatively, the Encrypt Password function in Rhapsody IDE can be used if the password is being set directly as a message property, without using a Rhapsody variable.
Base64
Function |
Description |
---|---|
|
Decodes a Base64 value to a string:
|
decodeBase64ToByteArray(value) |
Decodes a Base64 value to a byte array:
|
|
Encodes a value to Base64 value:
|
dataMap
dataMap functions translate a string or field using a translation table. Refer to dataMap Functions for details.
Lookup Tables