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

Initialize variable inside a Apply to Each loop

(0) ShareShare
ReportReport
Posted on by

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
    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

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