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 on webpage ...
Power Automate
Answered

JavaScript on webpage returning [object Object] but code works in Console.log

(0) ShareShare
ReportReport
Posted on by 259

I have some code I am trying to run in a "Run JS Function on web page" but it just returns [object Object] I am just trying to return a string... a number where one of the text boxes on the page contains '09'.

 

Any ideas? - thanks guys!

 

 

 

function ExecuteScript() {

function findTextboxContainingValue09(pattern) {
 // Get all textboxes in the document
 var textboxes = document.querySelectorAll('input[type="text"]');
 
 // Loop through each textbox
 for (var i = 0; i < textboxes.length; i++) {
 // Check if the ID of the current textbox starts with the given pattern
 if (textboxes[i].value.includes('09')) {
 // Extract the number at the end of the ID
 var idParts = textboxes[i].id.split('$');
 var number = parseInt(idParts[idParts.length - 1]);
 // Return the number if it's a valid number
 if (!isNaN(number)) {
 return number;
 }
 }
 }
 
 // If no textbox with the specified pattern is found, return null
 return null;
}

// Call the function with the specified pattern
var textboxNumber = findTextboxContainingValue09('SSR_RSRCH_SCHLS_SSR_SCHOL_TYPE$');

// Log the result to see if it returns the correct number
//console.log(textboxNumber);


}

 

 

  • NathanAlvares24 Profile Picture
    1,714 Moderator on at

    Hi @beebul !

     

    console.log is only used to show in the log the output but it won't store anything.

    Please add return keyword so that this output gets reflected onto the output variable of this action.

     

    So you need to add like this at the end:

    return(textboxNumber)

     

    Like in below pic:

    NathanAlvares24_0-1715839666729.png

    When you use return keyword the output will reflect onto the variable 'Result'.

     

    I hope this helps.

  • beebul Profile Picture
    259 on at

    Thanks I tried that but it's still [object Object].

     

    I just tried to Console.log("Hi"); to the page and that works. 

     

    updated code:

     

     

     

    function ExecuteScript() {
    
     function findTextboxContainingValue09(pattern) {
     // Get all textboxes in the document
     var textboxes = document.querySelectorAll('input[type="text"]');
    
     // Loop through each textbox
     for (var i = 0; i < textboxes.length; i++) {
     // Check if the ID of the current textbox starts with the given pattern
     if (textboxes[i].value.includes('09')) {
     // Extract the number at the end of the ID
     var idParts = textboxes[i].id.split('$');
     var number = parseInt(idParts[idParts.length - 1]);
     // Return the number if it's a valid number
     if (!isNaN(number)) {
     return number;
     }
     }
     }
    
     // If no textbox with the specified pattern is found, return null
     return null;
     }
    
     // Call the function with the specified pattern
     var textboxNumber = findTextboxContainingValue09('SSR_RSRCH_SCHLS_SSR_SCHOL_TYPE$');
    
     // Log the result to see if it returns the correct number
     //console.log(textboxNumber);
     return (textboxNumber);
    }

     

     

     

  • NathanAlvares24 Profile Picture
    1,714 Moderator on at

    Hi @beebul !

     

    NathanAlvares24_0-1715840529490.png

    Please check if you have this extension in your browser

  • beebul Profile Picture
    259 on at

    Yes I do and I can send basic javascript to a page

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @beebul 


    First try with alert, don’t add return.. something like this:

    alert(text box number);

    alert(text box number.innertext);

    alert(text box number.innerhtml);

    alert(text box number.textContent);


    note: since I am suggesting from mobile please check and use the right syntax.

     

     

    once it’s showing right value then use the same to return it



    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀

  • eetuRobo Profile Picture
    4,589 Super User 2026 Season 2 on at

     [object Object] usually means error. 

    Maybe try simplify the code to just get some basic element and see if that returns something other than [object Object]
    Also try without the for each loop. Then when you find where it gives error its easier to start to fix it.

  • beebul Profile Picture
    259 on at

    I think my actual problem is that I am trying to target a modal window/ new frame, there actually isn't' anything wrong with the JavaScript, I got it working in the console for the window but I can't seem to target the run JS to focus on that window in PAD 😞

  • Verified answer
    beebul Profile Picture
    259 on at

    My fix was actually to target the iFrame in JavaScript and then run the code.

     

    Thanks guys

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

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 273 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 235

#3
David_MA Profile Picture

David_MA 172 Super User 2026 Season 2

Last 30 days Overall leaderboard