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 functions r...
Power Automate
Unanswered

JavaScript functions return [object Object] instead of text - Power Automate Desktop

(2) ShareShare
ReportReport
Posted on by 4

So,

I'm pretty new with Power Automate Desktop. I started using it for 3 days now and I was doing a little experiment: I wanted to get all the name of games the are stored on the website https://www.esrb.org/ .
I tried getting the name with a lot of JavaScript function (because somehow the "extract data" is broken on this website) but I keep getting this thing where I can't get the correct value.


Screenshot 2023-02-21 015113.png

 

I really don't know what I am doing wrong.
As shown in the image below, I also tested the JS scripts on the console and they work fine.

 

Screenshot 2023-02-21 015519.png

 

How can I solve it?

I have the same question (0)
  • Kyle_Con Profile Picture
    3 on at

    I'm also having the same problem...

    Kyle_Con_0-1678299589922.png

     

    Kyle_Con_2-1678300778435.png

     

     

     

     

     

  • Pavel_NaNoi Profile Picture
    1,074 on at

    Try this, worked for me, return document.querySelector("#results > div:nth-child(1) > div.heading > h2 > a").textContent;

    (credit to ChatGPT for this one)

     

  • ValRab Profile Picture
    7 on at

    Still happening, I'm guessing it's one of the lastest updates? 

     

    Tried casting it to string, passing it to a variable creating a dom component and retrieving it's textContent and innerText, no luck

  • MARKYQD Profile Picture
    4 on at

    https://www.freecodecamp.org/news/object-object-in-javascript-meaning-in-js/ 

     

    Checkout this post! 

  • ValRab Profile Picture
    7 on at

    Although this might some people the current problem is in PAD not in the code, you can even try to return with something like 

     

    return 'test' 

     

    And it will return [object Object]

  • MARKYQD Profile Picture
    4 on at

    Maybe it's because you're occupying PA variables. I solved the problem by adding quotation marks in the variable namesimage.png

  • ValRab Profile Picture
    7 on at

    Long story short: The [object Object] might be returned if the code has an error of any kind, in my case I was using the wrong browser instance so It wasn't finding the window variables I was looking for.

     

    Maybe the action should be able to catch those kind of errors instead of leaving us in the dark.

  • waynewalls Profile Picture
    74 on at

    Debugging the JavaScript submitted to PAD's Run JavaScript action is occasionally a real pain-point.  That can be especially true when the returned value is null or undefined. 

     

    I've started to include something like the following in almost all my JavaScript submitted through PAD's action:

    if (variable_to_be_returned == null){
     variable_to_be_returned = "null or undefined"
    }
    return variable_to_be_returned;

    This detects both null and undefined because:

     null == undefined

    This at least separates out when you are getting null or undefined from some other object--which is often useful for me.

  • eshaani Profile Picture
    4 on at

    A workaround that worked for me was to set a global variable and just separate the return value into it's own function.

     

    function ExecuteScript() {
    function doSomethingElse(res) {
     asdf = res
     return asdf
    }
    
    
    
    fetch("https://1.1.1.1/cdn-cgi/trace")
     .then(function (result) {
     // If using a full function expression: return the promise
     return result.text() 
     })
    .then((newResult) => doSomethingElse(newResult))
    .catch((error) => console.error(error));
     }
    function ExecuteScript() { 
    
    
    return window.asdf;
    
    
    }

     




     

  • Mohamed_Rila Profile Picture
    2 on at

    @BranzinoAlForno ,

    Try by using JSON.stringify(JSONResponse);

     

    Change the JSONResponse value to the value that you're trying to return. It'll work, If not means ping me so that we can try with different approach.

     

    Hope this solution helps you!

    If your problem is solved then please change the state to solved.


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 June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 227

#2
David_MA Profile Picture

David_MA 204 Super User 2026 Season 1

#3
Valantis Profile Picture

Valantis 177

Last 30 days Overall leaderboard