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

Notifications

Announcements

Community site session details

Community site session details

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

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 2 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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard