1

I've created a scheduled flow and added initialize variables to format how the data shows in my email notification. This works fine in my other flow - when a new item is created. But for this scheduled flow, and get items action, I'm getting the error:

'Flow save failed with code 'InvalidVariableInitialization' and message 'The variable action 'Initialize_variable_4' of type 'InitializeVariable' cannot be nested in an action of type 'Apply_to_each_3'.'.

Is there a way to fix this? Any guidance would be very much appreciated. Thanks so much!

enter image description here

enter image description here

enter image description here enter image description here enter image description here

enter image description here enter image description here

19
  • Is there any reason for creating a variable inside apply to each action. It is best practice to create a variable at the start of the flow to avoid any errors. Try initializing variable at the start of the flow outside apply to each action. Let me know if it resolves this error message. Commented Apr 20, 2023 at 8:45
  • Hi Ganesh, thanks for looking into this. I've actually created the variable outside but it's automatically adding it inside the apply to each action. I suspect it's probably because in the value field, I've added the 'Survey Feedback' from dynamic content.
    – Gen_C
    Commented Apr 20, 2023 at 9:00
  • Wait a minute, I am writing a answer with more explanation and easier/cleaner solution without using apply to each action and variables. Commented Apr 20, 2023 at 9:02
  • Check my answer given below. Let me know if it works for you or if you have any doubts. Commented Apr 20, 2023 at 9:09
  • Hi Ganesh, I've tried the given instructions but I'm probably doing something wrong because the survey feedback data showing in my email notification includes other items survey feedback data too :(
    – Gen_C
    Commented Apr 21, 2023 at 3:26

2 Answers 2

0

The initialization of variables should always occur at the start of the flow. If you create a variable after the trigger action of the flow, it can result in errors.

When defining a variable inside an Apply to each loop, it's best practice to make the variable global and use it inside the loop in a manner that it gets iterated as intended.

In your case move action Initialize Variable 4 to the top after trigger and it should resolve the issue.

2
  • 1
    Hi Pradip, thanks for looking into this. I tried adding the Initialize Variable 4 to the top but it's automatically putting it inside an Apply to each loop. It's probably because I'm using a dynamic content.
    – Gen_C
    Commented Apr 21, 2023 at 3:29
  • @Gen_C You can have dynamic content in action without any issues. Just initialize a variable with an empty value at the beginning, and within your "Apply to each" action, use the "Set Variable" action to set the value as dynamic content.
    – Pradip R.
    Commented Apr 21, 2023 at 16:34
0

You are receiving this error because you are trying to initialize a variable inside apply to each action which is not supported in Power Automate.

It is recommended and a best practice to initialize a variable at the start of the flow to avoid any errors.

So, try initializing all your variables at the start of the flow after flow trigger before any other actions.


If you want a cleaner flow without using any variables and apply to each action, you can use flow as shown below:

enter image description here

Expressions used:

In Select action:

@item()?['SurveyFeedback']

Where SurveyFeedback is the internal name of my SharePoint column. Follow this to find the internal name of your SharePoint column: How to find the Internal name of columns in SharePoint Online?

In Compose action:

@{join(body('Select_-_Collect_Survey_feedbacks'),'<br/>')}

Output Email:

enter image description here

Note: You can also avoid Compose action and use expression to add <br/> directly in email body as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.