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 / Run JavaScript functio...
Power Automate
Unanswered

Run JavaScript function on web page returns data as well as function code

(0) ShareShare
ReportReport
Posted on by 51

When I run the following code to capture ld+json content, it returns the ld+json content as well as JS code at the end of the JSResult variable. This prevents the Convert JSON to customer object action from running. Any ideas why that code is being returned and how to prevent it?

 

Thanks, John

 

Run JavaScript function on web page JavaScript Function: 

function ExecuteScript() {
var headings = document.evaluate("//script[contains(., 'gtin')]", document, null, XPathResult.ANY_TYPE, null );
var thisHeading = headings.iterateNext();
var result = "";
while (thisHeading) {
result += thisHeading.innerText;
thisHeading = headings.iterateNext();
}
return result;
}

 

Weird code at end of JSResult variable.

var result = undefined; try{ result = (function ExecuteScript() {
var headings = document.evaluate("//script[contains(., 'gtin')]", document, null, XPathResult.ANY_TYPE, null );
var thisHeading = headings.iterateNext();
var result = "";
while (thisHeading) {
result += thisHeading.innerText;
thisHeading = headings.iterateNext();
}
return result;
})();;}catch(e){}; document.documentElement.setAttribute("result", result); document.documentElement.setAttribute("complete", "true");

I have the same question (0)
  • Verified answer
    jfk86d Profile Picture
    51 on at

    It appears that PAD may have a bug with its JavaScript action. The above code appears to run an extra loop in the while and for some reason echos the action's code. To prevent this I modified the loop as follows. This prevents the echo of the action's code to be included in the results.

     

    John

     

    function ExecuteScript() {
    var txtJSON= "[";
    var headings = document.evaluate("//script[contains(., 'gtin')]", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null );
    for(var i = 0; i < headings.snapshotLength-1; i++) {
    txtJSON += headings.snapshotItem(i).innerText;
    if (i < headings.snapshotLength-2) {
    txtJSON += ", ";
    }
    }
    txtJSON += "]";
    return txtJSON;
    }

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 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard