Skip to content
RTILA Web Business Automation
  • Home
  • Features
  • Pricing
  • Marketplace
  • Support
    • Documentation

Cart

RTILA Web Business Automation
  • Home
  • Features
  • Pricing
  • Marketplace
  • Support
    • Documentation
Free Download
Free Download

Billing & Licensing

10
  • Change License’s registered email address
  • Upgrade a License
  • Manage License Activation Count
  • RTILA Studio local database
  • Standalone Exe Antivirus False Positive Alert
  • Team Member Activation URL & License
  • AppSumo Codes Redemption
  • Download & Activate RTILA Studio
  • AppSumo Code Stacking & Upgrade
  • Mac OS Installation Warning

Custom Commands

36
  • WordPress Posts via API (beta)
  • Webhook Send Request
  • Target Text Before After
  • Download File to Folder
  • Clipboard Copy & Paste
  • ChatGPT API Full Control
  • Generate Random Numbers and Text
  • Regex & JS Filters
  • API Bridge Get Post Requests
  • WhatsApp API send MSG
  • GET HTML
  • Slack Notification Command
  • Target Elements With Text Value
  • Directory Get Files Path
  • Folder and File Monitoring
  • Get iFrame URL
  • Get File Content
  • Verify License Easy Digital Downloads
  • Save Variable to File
  • Rename File
  • Move File to New Directory
  • Delete File
  • Mouse Events
  • Get System Info
  • Airtable Get & Update Records
  • Email Send Via SMTP
  • Wait For Element to disappear
  • OCR Passport Reader
  • Target Element in Shadow Dom
  • Airtable Get Records
  • Airtable Update Records
  • Sanitize URL
  • Email Verification
  • Get Hardware ID HWID
  • Timestamp Unix and UTC
  • Switch Tab Focus Command

How-To & Tutorials

42
  • How to target a CSS element
  • Change default Browser
  • Export Results to a CSV file
  • Profile Session Feature
  • OCR Feature: read text from images
  • Auto Download Pinterest Images
  • Save current URL using JavaScript
  • Search & Filter Projects
  • Error handling Strategy
  • Working with Arrays and Objects in RTILA
  • Auto Comment On WordPress Posts
  • Run Automations in Silent Mode
  • License Check for Standalone Executables
  • Trigger Standalone Bots via Command lines
  • How To Find Custom Collections For List type Datasets
  • Correcting & Completing Auto-Recorder Commands
  • RTILA WordPress Plugin installation & configuration
  • Using Developer Tools In RTILA Studio
  • Create A Project From Scratch
  • Bring back disappearing commands & properties
  • Export & share an RTILA project file
  • Install Browser Extensions using Profile Session
  • How To Fill a Form Using Generic Form Filler Child-Project
  • Project Settings: Import URLs manual entry, From File, From Project, and Read XML Sitemap
  • Project Settings: Import URLs manual entry
  • Use Local Storage Variable to scrape Do-follow Links
  • Schedule Launch of Automations
  • Email Results File via Gmail
  • Read from Google Sheets & Post on WordPress
  • Website Load Testing Automation
  • Read data from a txt or csv file
  • Downloading files
  • Open in a New tab
  • Using filters to complete a URL
  • Choosing the right collection
  • Set a Counter with JavaScript
  • Setup reCAPTCHA Resolution
  • Woo Categories & ChatGPT API
  • Login to Google Account & share profile session
  • Google Search Baby Steps
  • Auto-Recorder as a 1st step
  • Standalone Executable Bots

Official Commands

58
  • List Command
  • Incogniton Anti-detect browser
  • Save results to file command
  • RTILA Cloud API Documentation
  • FTP / SFTP Command
  • Custom Commands
  • Integrations
  • RPA & Desktop OS Commands
  • Add And Configure Dataset Properties
  • Inspection Panel Interface & Elements
  • Config & binaries files for Standalone
  • Focus On Element Command
  • Go To Url Command
  • Scroll Element Command
  • Execute JavaScript Code command
  • Reload Page Command
  • Compare Variables Condition
  • Take Screenshot Command
  • Smart Variable (ChatGPT API)
  • Child Projects
  • Confirm (Dialog Box) Command
  • Populate Text Field Command
  • Hover Mouse On Element Command
  • Download Page Command
  • Stop Automation Command
  • Log Message Command
  • Input (prompt box) Variable
  • Extract Results Command
  • Wait for Element to Appear Command
  • Selector (DOM element)
  • Check Radio Input Command
  • Dynamic Variable (JavaScript Code)
  • Static Variables
  • Set Checkbox State Command
  • Set Dropdown Value Command
  • Press a Keyboard Key Command
  • Upload File Command
  • Double Click On An Element Event
  • Click On An Element Event
  • Switch Browser Identity Command
  • Slack Notification Command
  • Save as Pdf Command
  • Go Back To Previous Page Command
  • Go Forward To Next Page Command
  • Proxies Built-In Rotation
  • External Proxy Rotation API
  • Regular Expressions
  • Mock Location Command
  • Close Page Command
  • Desktop Notification Command
  • Command Folder
  • Clear Cookie Command
  • Change Page Size Command
  • Break Loop Command
  • DataSet Types
  • Link Crawler Command
  • Alert Message Command
  • Wait Commands
  • Home
  • Docs
  • Official Commands
  • Dynamic Variable (JavaScript Code)
View Categories

Dynamic Variable (JavaScript Code)

6 min read

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.

Objective #

The primary purpose of this command is to let you write and run your own custom JavaScript code directly inside the browser context. You can input your code into the Dynamic Variable command field, and RTILA will execute it in the target page. The result of your script will be automatically stored in a variable named after your command. You can then reuse this result in any subsequent RTILA command or flow by referencing it with the {{MyVariableName}} syntax.

How to add a Dynamic Variable to your flow #

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.

  1. This refers to the ID of the variable which you can call later to get the value of this variable
  2. Edit the name of the dynamic variable describing what value it would contain
  3. 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
  4. 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.
  5. This allows you to combine different pieces of data or text together
  6. 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’ );

🧪 Debug Tip: Log VALUE before returning
At the bottom of your custom JS code just add this line:
console.log(“VALUE:”, VALUE);
This helps you check if your script is producing the expected value inside the browser.

Copy CodeCopiedUse a different Browser
console.log("VALUE:", VALUE);

Common Examples of Dynamic JS Code #

Get Current URL #

Copy CodeCopiedUse a different Browser
VALUE=window.location.href
console.log("VALUE:", VALUE);

Replace strings in current variable value #

Copy CodeCopiedUse a different Browser
VALUE=VALUE.replace('allXX','byYY' );
console.log("VALUE:", VALUE);

Prepend current variable value #

Copy CodeCopiedUse a different Browser
VALUE = "YourTextHere" + VALUE;
console.log("VALUE:", VALUE);

Append current variable value #

Copy CodeCopiedUse a different Browser
VALUE = `${VALUE}YourTextHere`;
console.log("VALUE:", VALUE);

Concatenate other variable commands values #

Copy CodeCopiedUse a different Browser
VALUE = '{{DOMSelectorVariable}}'+'{{StaticVariable}}'+'{{DynamicVariableX}}';
console.log("VALUE:", VALUE);

Sanitize other variable command values #

Copy CodeCopiedUse a different Browser
VALUE = '{{DOMSelectorVariable}}'.toLowerCase().replace(/[^a-z]/g, '');
console.log("VALUE:", VALUE);

Get The Current Date #

Copy CodeCopiedUse a different Browser
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}`
console.log("VALUE:", VALUE);

Get The Current Date & Time #

Copy CodeCopiedUse a different Browser
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;
console.log("VALUE:", VALUE);

Get The Current Value of a LocalStorage Variable #

Copy CodeCopiedUse a different Browser
VALUE=window.localStorage.getItem('Replace this with your local storage variable');
console.log("VALUE:", VALUE);

Get TimeStamp In Seconds #

Copy CodeCopiedUse a different Browser
VALUE = Date.now();
console.log("VALUE:", VALUE);

Get The Current IP Address #

Copy CodeCopiedUse a different Browser
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));
console.log("VALUE:", VALUE);

RTILA Dynamic JS Code Command (Advanced Guide) #

The Dynamic JS Code command in RTILA allows you to execute custom JavaScript code inside a page and return a result into a dynamic variable (e.g., {{MyVariable}}). This is a powerful feature for scraping, automation, conditional logic, and data extraction — even from complex or Shadow DOM elements.

📌 What This Command Does #

  • Executes JavaScript code inside the target page context (browser-side).
  • Supports asynchronous operations like delays, button clicks, and tab handling.
  • Stores the final result into a variable that can be reused in the next steps using {{MyVariable}}.

🛠️ How It Works Internally #

Under the hood, the command runs your JS code like this:

Copy CodeCopiedUse a different Browser
commandValues = await page.evaluate(async function (jsCode) {
  let VALUE;
  const asyncCode = `(async () => {
    ${jsCode}
    return typeof VALUE !== 'undefined' ? VALUE : 'VALUE_NOT_SET';
  })()`;
  return await eval(asyncCode);
}, command.dynamicVariable);

💡 Important: #

VALUE is a reserved keyword in RTILA — it is used to pass your result into the dynamic variable.

Do NOT declare VALUE using let, const, or var. The VALUE variable is already pre-declared by RTILA in the evaluation scope.
Your custom JavaScript code should only assign a value to it, like this:

Copy CodeCopiedUse a different Browser
VALUE = 'final result';

✅ Basic Example (Extract Page Title) where result {{MyVariable}} will contain and output the saved page title.

Copy CodeCopiedUse a different Browser
VALUE = document.title;

✅ Advanced Example: Click in Shadow DOM & Extract New Tab URL #

Copy CodeCopiedUse a different Browser
const delay = ms => new Promise(res => setTimeout(res, ms));
const host = document.querySelector('li:nth-of-type(1) svelte-component[type="ProfileCard"]');
if (!host) throw new Error("ProfileCard host not found.");
const shadowRoot = host.shadowRoot;
if (!shadowRoot) throw new Error("Shadow root not accessible.");
const linkedinButton = shadowRoot.querySelector('button[data-testid="social-button"] i.fa-linkedin-in');
if (!linkedinButton) throw new Error("LinkedIn button not found.");
const button = linkedinButton.closest('button');
if (!button) throw new Error("Button wrapper not found.");
let newTab = null;
const originalOpen = window.open;
window.open = function (...args) {
  newTab = originalOpen.apply(this, args);
  return newTab;
};
button.click();
await delay(5000);
window.open = originalOpen;
let finalUrl = 'cross-origin-or-unknown';
try {
  if (newTab && newTab.location && newTab.location.href) {
    finalUrl = newTab.location.href;
  }
} catch (e) {
  finalUrl = 'cross-origin-or-unknown';
}
newTab.close();
VALUE = finalUrl;
console.log("VALUE:", VALUE);

🧩 Best Practices

DoDon’t
✅ Always assign your final result to VALUE❌ Don’t wrap VALUE assignment inside try-catch unless handled properly
✅ Use await for async actions like delays❌ Don’t assume window.open() will always be same-origin
✅ Console.log VALUE for debugging❌ Don’t re-declare VALUE inside a different scope
✅ Test from DevTools Console before inserting❌ Avoid eval() inside your code — it’s already used by RTILA

⚠️ Common Pitfalls #

🔁 Problem: {{MyVariable}} is blank or crashes RTILA #

Cause: Your code didn’t assign VALUE in the correct (top-level) scope.
Fix: Ensure this line runs in the main body, not inside another function or suppressed try-catch:

Copy CodeCopiedUse a different Browser
VALUE = yourResult;

🧪 Reminder Tip: Log VALUE before returning
This helps you check if your script is producing the expected value inside the browser.

Copy CodeCopiedUse a different Browser
console.log("VALUE:", VALUE);

🧰 Use Cases #

  • Extract data from dynamic or Shadow DOM
  • Wait for page elements before acting
  • Interact with modals, dropdowns, and iFrames
  • Capture data from newly opened tabs
  • Inject conditional logic before proceeding
    Still stuck? How can we help?

    How can we help?

    Updated on 21/05/2025
    Check Radio Input CommandStatic Variables

    Powered by BetterDocs

    Table of Contents
    • Definition
    • Objective
    • How to add a Dynamic Variable to your flow
      • Configure a Dynamic Variable
    • Dynamic Variable In Action
    • Useful JavaScript code lines for Dynamic Variable
      • Applicability to Properties values
      • Common Examples of Dynamic JS Code
      • Get Current URL
      • Replace strings in current variable value
      • Prepend current variable value
      • Append current variable value
      • Concatenate other variable commands values
      • Sanitize other variable command values
      • Get The Current Date
      • Get The Current Date & Time
      • Get The Current Value of a LocalStorage Variable
      • Get TimeStamp In Seconds
      • Get The Current IP Address
      • RTILA Dynamic JS Code Command (Advanced Guide)
        • 📌 What This Command Does
        • 🛠️ How It Works Internally
      • 💡 Important:
      • ✅ Advanced Example: Click in Shadow DOM & Extract New Tab URL
        • ⚠️ Common Pitfalls
          • 🔁 Problem: {{MyVariable}} is blank or crashes RTILA
        • 🧰 Use Cases

    INFO & LEGALS

    PRICING
    PAYMENTS & REFUND
    COOKIES - PRIVACY
    LICENSE AGREEMENT

    DOWNLOADS

    BOT LAUNCHER
    RTILA STUDIO ON GITHUB
    BOT & TEMPLATES
    PARTNERSHIPS

    RESOURCES

    VIDEO TUTORIALS
    DOCUMENTATION
    SUPPORT PORTAL
    FB COMMUNITY SUPPORT

    stay in touch

    Subscription Form

    follow us on

    • Facebook
    • YouTube
    • RTILA LinkedIn Page
    Copyright © RTILA CORPORATION