Definition #
Dynamic variables are variables whose values can be changed at runtime, meaning their values can be updated during the execution of the program. In other words, the value of a dynamic variable is not fixed or predetermined at the time of declaration and you can use it to capture, modify and pass data between different sections of RTILA automation flows. Dynamic variables in JavaScript are particularly useful for storing and updating data that may change during the execution of a program, such as a user input or the results of a computation.
Add a Dynamic Variable #
To add the Dynamic variable, you will need to go to the variables tab of a new command interface and search for it. After finding the variable and adding it, you can edit its value and set some other configurations.
Configure a Dynamic Variable #
To add a dynamic variable, you will need to go to the variables tab of a new command interface and search for it. After finding the variable and adding it, you can edit its value and set some other configurations.
- This refers to the ID of the variable which you can call later to get the value of this variable
- Edit the name of the dynamic variable describing what value it would contain
- Here you can enter a javascript code that contains the returned value of the dynamic variable regaining with “VALUE=” for example VALUE=window.location.href
- A sequence of characters that forms a search pattern. For example, you can use regex to find all email addresses in a document or to extract all the numbers in a string.
- This allows you to combine different pieces of data or text together
- Enabling text spinning in a static var means allowing a static variable to store multiple versions of the same text, each with different wordings and phrasings, so that when the variable is called in a program or script, a different version of the text is returned each time
Dynamic Variable In Action #
Here is an example of using “Dynamic Variable ” with JavaScript code to get the current URL of a page and call the variable data (in this case the current page URL) in an alert message
Useful JavaScript code lines for Dynamic Variable #
Applicability to Properties values #
The shared JavaScript lines of codes can also be used for Properties as a Filter > Actions. The only difference is that you need replace every instance of VALUE by FIELD_VALUE when used on the Property side. For instance instead of VALUE=VALUE.replace(‘allXX’,’byYY’ ); you would use FIELD_VALUE=FIELD_VALUE.replace(‘allXX’,’byYY’ );
Replace strings in current variable value #
VALUE=VALUE.replace('allXX','byYY' );
Prepend current variable value #
VALUE = "YourTextHere" + VALUE;
Append current variable value #
VALUE = `${VALUE}YourTextHere`;
Concatenate other variable commands values #
VALUE = '{{DOMSelectorVariable}}'+'{{StaticVariable}}'+'{{DynamicVariableX}}';
Sanitize other variable command values #
VALUE = '{{DOMSelectorVariable}}'.toLowerCase().replace(/[^a-z]/g, '');
Get The Current Date #
let currentDate = new Date();
let year = currentDate.getFullYear();
let month = currentDate.getMonth() + 1; // add 1 to get the actual month (0-based index)
let day = currentDate.getDate();
VALUE = `Today's date is ${year}-${month}-${day}`
Get The Current Date & Time #
let currentDate = new Date();
let year = currentDate.getFullYear();
let month = ('0' + (currentDate.getMonth() + 1)).slice(-2);
let day = ('0' + currentDate.getDate()).slice(-2);
let hours = ('0' + currentDate.getHours()).slice(-2);
let minutes = ('0' + currentDate.getMinutes()).slice(-2);
let seconds = ('0' + currentDate.getSeconds()).slice(-2);
VALUE= 'Date / '+ year + '-' + month + '-' + day + ' Time /' + hours + ':' + minutes + ':' + seconds;
Get The Current Value of a LocalStorage Variable #
VALUE=window.localStorage.getItem('Replace this with your local storage variable');
Get TimeStamp In Seconds #
VALUE = Date.now();
Get The Current IP Address #
VALUE= fetch('https://api.ipify.org?format=json').then(response => response.json()).then(data => FIELD_VALUE = data.ip).catch(error => console.error('Error fetching public IP address:', error));