Retrieving Variables Values : RMPApplication.get() vs "[[ ]]"
These syntaxes are used to retrieve variable values, and both have a specific behavior. Let's see when and why you should or shouldn't use them.
Let's take 4 examples of widgets:
- A text input widget, variable firstname.
- A number input widget, variable amount.
- A multi selection list widget, whose value variable is product_ids.
- An array widget, whose variable is items_t
RMPApplication.get() syntax
How to use it
Technically, you expect to have firstname being a string, amount being a number, product_ids being an array and items_t being a json.
You have to keep in mind that RMPApplication.get("xxx")
will always return a string, so you will have to cast it to a number, array or json in your scripts:
1 2 3 4 |
|
Where to use it
- in js widgets
- in prelaunch scripts on buttons
- in .js files
Where/When you shouldn't use it
Don't use this syntax in JS dynamic rules on widgets, because it will be executed only once (see section on "[[ ]]"
syntax for more details).
"[[ ]]" syntax
How to use it
Technically [[myvar]]
will be replaced by the characters as value of myvar.
If you expect a string variable, then you must use "[[ ]]"
syntax. Ex:
1 |
|
If you expect a variable that is NOT a string (it's a number, or an array, or a json), you must use [[ ]]
syntax instead (note that there is no double quotes " "). Ex:
1 2 3 |
|
If you don't follow above rules:
1 2 3 4 |
|
Where to use it
Keep "[[ ]]"
syntax for the dynamic rules on widgets: it not only means you intend to retrieve a variable value, but also you are listening to this variable.
Where/When you shouldn't use it
- Special characters
If the RunMyProcess variable is a string and contains any special characters (ex: carriage return), you should't use "[[ ]]"
syntax since you'll get a JS execution error.
Ex: if you configure a multi-rows text input address, and enter a value with carriage returns: Street\n\City\nCountry :
1 2 3 4 5 |
|
So in that case, do rather use:
1 |
|
- In a definition of a function
If you intend to create a function that calls firstname variable and display it:
1 2 3 |
|
If you call the function above, you will get the value firstname had at the moment you defined the function. So you must use this definition instead:
1 2 3 |
|
Please give details of the problem