Skip to main content

Notifications

Power Automate - Using Connectors
Answered

Problem with variable initialized in foreach loop

(0) ShareShare
ReportReport
Posted on by 691

Hello,
When I initialize the variable "Montant_Actuel" it automatically goes into a foreach loop, and then when I save my WorkFlow it gives me an error telling me that a variable cannot be initialized in a foreach loop.

The value I give to my variable is a value that comes from one of my SharePoint lists.
How do I remove my variable from the foreach loop?

s44_0-1640857824746.png

 

Thanks in advance !

  • Verified answer
    vikulkar Profile Picture
    vikulkar on at
    Re: Problem with variable initialized in foreach loop

    Hi @s44 ,

    You would want to check what type of column is "Montant_Actuel" in the SP list?

    If it is an array and something that can hold multiple values, the PowerAutomate flow automatically generates an ApplyToEach loop. In which case you will have to initialize your variable as an array.

     

    OR 

     

    If you know the column always holds a single value then you can "initialize variable" before the loop and then use a "Set variable" action inside the loop as shown below.

     

    Community09.png

    Note: You can only use set variable inside a loop and not initialize inside a loop.

     

    Thanks and Regards,

    Vikas K

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

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,907

Leaderboard

Featured topics