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 / Initialize variable in...
Power Automate
Answered

Initialize variable inside a Apply to Each loop

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I have a flow with a JSON array I get via Http call.

 

 

{
 "NAVN": "",
 "NAVN 2": "",
 "ADRESSE": "",
 "ADRESSE 2": "",
 "KONTAKTNAVN": "",
 "POSTNR": "",
 "BY": "",
 "Email": "",
 "Mobil": "",
 "FIRMA/PERSON": "",
 "Indmeldelseskilde": "",
 "ABONNEMENT": "",
 "Beløb": ""
 }

 

 

 The array can have 1 or many lines. 
What I need is to change the JSON names into some else, and for each item in the array. 
Up until now I have just used Initialize Variable action to change the names in the JSON since there was only one line. 
Now I have an array and I need to Initialize each item. 
I tried to do it in a Apply to each but get a "The operation 'Initialize variable' can only be used at top level.". 
Maybe it's just me but not being able to initialize inside the loop seems weird. 

Is there a work around or another way to do this properly?

Edit:
When I try to make an Initialize Variable to the JSON array Power Automate automatically makes an Apply to Each action and then says it can't be done. 

HjerteOlgen_0-1632009398807.png

 

 

Categories:
I have the same question (0)
  • Hardesh15 Profile Picture
    7,087 Super User 2024 Season 1 on at

    @Anonymous  Variable initialization can only be done at top level. You can not initialize variable inside Apply to each. Please initialize variable at top and use 'Set Variable' action inside apply to each loop.

    Please 'Thumbs Up' the posts that helped you and 'Mark as Solution' if my post answered your question.

    @Hardesh /Gopenly.in

     

  • Verified answer
    Community Power Platform Member Profile Picture
    Microsoft Employee on at

    I've found a Solution to my problem. 

    All I had to do was add a Data Operation Action, and in there choose the Select data operation. 
    This allowed me to rename the data in a single action without have to do it for every data row in the JSON array and then simple add the body (from the "Select - Setup JSON data name" action)  into an Apply for Each loop. From there the loop would choose each item in the array and I can then choose what do to with it. Here I'm using it to send the data to an API. 


    HjerteOlgen_0-1632227339513.png

     

     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 784

#2
Valantis Profile Picture

Valantis 581

#3
Haque Profile Picture

Haque 545

Last 30 days Overall leaderboard