cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
HjerteOlgen
Regular Visitor

Initialize variable inside a Apply to Each loop

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
HjerteOlgen
Regular Visitor

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

 

 

View solution in original post

2 REPLIES 2
Hardesh15
Super User
Super User

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

 

HjerteOlgen
Regular Visitor

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

 

 

View solution in original post

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,571)