web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / How to "Run Javascript...
Power Automate
Answered

How to "Run Javascript on a web Page" with the JS-code as a variable

(1) ShareShare
ReportReport
Posted on by 11

Hi guys,

 

I'm trying to run some custom Javascript with the ""Run Javascript on a web Page".

I've saved the javascript in a txt/js-file (tried both) and used "Read text from file" to save the variable.

 

When I run the javascript nothing really happens. The JS works if I don't use it as a variable..

 

Is it possible to achieve what im trying to do? 
I'm saving the JS as a text-value, standard encoding. And when I run the javascript I just initiate the variable %Javascript%.. but no javascript seems to run.

 

 

Categories:
I have the same question (0)
  • Verified answer
    Ewert99 Profile Picture
    11 on at

    Solved.

     

    Following worked:

     

    "function ExecuteScript(){ %Javascriptvariable%}

  • Suggested answer
    SH-09100920-0 Profile Picture
    2 on at
    Thank you for your help! I'm new to this. I would like to pass the variable Subtext to the JavaScript. I tried the following script, but it didn't work. Could you please explain this solution further? Many thanks!

    function ExecuteScript()
    {
    var myText = %Subtext%; // target variable
    var links = document.querySelectorAll('a');
    console.log('Function called with Subtext:', myText, links.length);
    for (var i=0; i<links.length; i++)
    {
    if (links[i].textContent==myText)
    {
    links[i].click();
    }
    }
    }
  • Suggested answer
    SaiRT14 Profile Picture
    1,990 Super User 2025 Season 1 on at
    Best practice steps:
    • Action: "Read text from file" (Load JavaScript file content into a variable %JavaScriptCode%).
    • Action (optional): "Replace" or "Trim" (Clean or format the variable content if needed).
    • Action: "Run JavaScript on web page" (Pass %JavaScriptCode% as the script to be executed).
    • Action: "Wait for web page to load" (Ensure page readiness before running the script).
    • Test and Monitor: Run the flow and monitor execution via the browser console.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 251 Super User 2026 Season 1

#2
Haque Profile Picture

Haque 239

#3
Expiscornovus Profile Picture

Expiscornovus 220 Most Valuable Professional

Last 30 days Overall leaderboard