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 / Javascript works in co...
Power Automate
Answered

Javascript works in console but returning blank output in Power Automate desktop

(1) ShareShare
ReportReport
Posted on by 7

I am trying to get rowCount of a HTML table using Javascript. The code works fine in console. but it is not saving the value to power automate. The code is below:

function countTableRows() {
var tbody = document.getElementById('MainTable1512446');
if (!tbody) {
console.log('tbody element not found.');
return 0;
}

var rows = tbody.getElementsByTagName('tr');
var rowCount = rows.length;

console.log('Number of rows:', rowCount);
return rowCount;
}

countTableRows();

The error is thrown when the output is converting to a number and used as a loopindex. i added a display message for debugging it shows blank. What could be the solution?

Console output.PNG
Flow.PNG
Error.PNG
  • Verified answer
    NathanAlvares24 Profile Picture
    1,714 Moderator on at

    Hi @tawheed-bscic !

     

    Can you try this instead:

     

    function countTableRows() {
    var tbody = document.getElementById('MainTable1512446');
    if (!tbody) {
    console.log('tbody element not found.');
    return 0;
    }
    
    var rows = tbody.getElementsByTagName('tr');
    var rowCount = rows.length;
    
    console.log('Number of rows:', rowCount);
    return rowCount;
    }

     

     

    The only thing which I removed is: countTableRows(); at the end.

     

    The reason is that there is no need to call the function when using this action from PAD. This PAD action will automatically call the function and return the result into the PAD variable, 'Result':

    NathanAlvares24_0-1720494910277.png

     

    It is different from how you normally run JavaScript on a webpage using the console as there you need to insert the function and then call that function (with parameters if any).

     

    So please do check this and let us know.

  • NathanAlvares24 Profile Picture
    1,714 Moderator on at

    Also I did notice that you have Power Fx enabled. Is that done by mistakenly or are you trying to attempt the use case using Power Fx?

     

    In any case, if you are doing the use case using Power Fx, you can continue doing so. But if done mistakenly, please try to create a new flow with Power Fx disabled as seen in below pic., copy those actions (Ctrl+A) then (Ctrl+C) and then paste (Ctrl+V) those same actions into your new flow which has Power Fx disabled

    NathanAlvares24_0-1720495544390.png

     

  • tawheed-bscic Profile Picture
    7 on at

    My problem is solved by removing the function call. For power FX needed to change some variable syntax. Thank you for your help. I am fairly new to power automate. Previously I used winAutomation. Although the process ran, it was very slow.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 229 Super User 2026 Season 2

#2
11manish Profile Picture

11manish 223 Super User 2026 Season 2

#3
Valantis Profile Picture

Valantis 136 Super User 2026 Season 2

Last 30 days Overall leaderboard