Skip to main content

Notifications

Power Automate - General Discussion
Unanswered

IS it possible to use javascript in a power automate flow?

(0) ShareShare
ReportReport
Posted on by 18

So, I have finally got my stations in an array variable, and now I want to loop through and print the station names in the body of the email step. In the attached photo you can see the part of the email body I am trying to loop through things. I have not done this before so here is what I am trying

 

@{
                // Dynamically populate station names
                foreach(var stationName in Station Names) {
                    <div style="width: 17%; border-bottom: 2px solid rgb(111, 249, 57); padding-bottom: 7px; text-align: center;">
                        @{stationName}
                    </div>
                }
            }
 

Station Names is the variable that hold the station names, and of course stationName being what should be printing the station names. am I headed in the right direction?

 

  • SamLed Profile Picture
    SamLed 2,326 on at
    Re: IS it possible to use javascript in a power automate flow?

    Hi @Bacon1,

     

    No JavaScript needed for what you want to accomplish, consider following flow design: 

    SamLed_0-1708002587518.png

     

    • I simulate your input data using first compose
    • In an Apply to each, I build div in a compose
    • Outside apply to each, I use an advanced Power Automate trick to get an array of DIVs by calling outputs of compose belonging to Apply to each and use join() to convert it to string. Power Automate won't propose it in Dynamic contents outside of the Apply to each, you have to write it as expression manually.

    Now, you've just to replace your "Station Names" variable  in your mail body by last compose outputs.

     

    [Edit] You can also achieve this without using loop:

    SamLed_0-1708005596066.png

     

    Select From: outputs('Data')

    Select map: item()?['Name']

     

    "No loop all DIVs" compose expression: 

    concat('<div style="width: 17%; border-bottom: 2px solid rgb(111, 249, 57); padding-bottom: 7px; text-align: center;">', join(body('Select_Names'), '</div><div style="width: 17%; border-bottom: 2px solid rgb(111, 249, 57); padding-bottom: 7px; text-align: center;">'), '</div>')

     

    ______________________________________________________________

    If I have answered your question, please Accept the post as solution.
    If you like my response, please Thumbs Up.

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,422

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,711

Leaderboard