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 Apps / Set variable in forall
Power Apps
Unanswered

Set variable in forall

(1) ShareShare
ReportReport
Posted on by 418

It looks like its not possible to set a variable in a forAll() loop.  Any way around this?

 

My overall problem is SQL Server API limitation.  I am running into too many records to patch for the 100 API calls per 10 seconds.  I wanted to try and create a large SQL statement and then run that with Flow.  

 

Within my forall() loop my plan was to append onto a string variable for each record in the collection.  

 

Thank you!VarInLoop.PNG

Categories:
I have the same question (0)
  • v-xida-msft Profile Picture
    on at

    Hi @samuelJ ,

    Do you want to set a variable within a ForAll function?

     

    Setting a variable within a ForAll function is not supported within PowerApps currently. If you would like this feature to be added in PowerApps, please submit an idea to PowerApps Ideas Forum:

    https://powerusers.microsoft.com/t5/PowerApps-Ideas/idb-p/PowerAppsIdeas

     

    As an alternative solution, I think collection could achieve your needs. On your side, you could consider use Collection to store the string value instead of the Set function. Please consider take a try with the following workaround:

    Clear(SQLStatementCollection);
    ForAll(
     toUpdateSmall,
     Collect(SQLStatementCollection, "abc")
    )

    If you want to concat these values within the SQLStatementCollection using a space (' '), please use the following formula (set Text property of a Label to following😞

    Concat(SQLStatementCollection, Value & " ")

     

    In addition, if you want to store the column value from your toUpdateSmall collection into the SQLStatementCollection, please modify above formula as below:

    Clear(SQLStatementCollection);
    ForAll(
     toUpdateSmall,
     Collect(SQLStatementCollection, ColumnNameFromtoUpdateSmall)
    )

    Please consider take a try with above solution, check if the issue is solved.

     

    Best regards,

  • Community Power Platform Member Profile Picture
    on at

    This would be extremely helpful to implement, as I was trying to use a ForAll last week to loop through the values in a collection to Set variables attached to the Default properties of various input text boxes, using Switch expressions.

     

    ForAll(

         collectionName,

         Switch (

              collectionName.key1 = val1, Set(defaultInput1, collectionName.key1),

              collectionName.key2 = val2, Set(defaultInput2, collectionName.key2),

              collectionName.key3 = val3, Set(defaultInput3, collectionName.key3)

        )

    )

     

    I was attempting the above to load data from my collection into input text / numeric boxes in the OnVisible screen event so a user could read the previously saved data and be able to update it. I'm still looking for a workaround..

  • tsiddiquee Profile Picture
    5 on at

    I'm having the same issue as well. Were there any solution/update to this?

  • CU10051026-0 Profile Picture
    on at

    It's a bit of a pain not having access to variables in a ForAll but using a collections works well - though it does make the "code" a bit more difficult to read.  This is how I do it:

     

    Add a line to the Form OnVisible to reset the collection (unless you're using the variable like a Global in which case put it in the App OnStart)

    ClearCollect(colVariables, {colvarVariableOne:""});

     

    Then to read the value use

    First(colVariables).colvarVariableOne

     

    And to set the value use:

    Patch(colVariables, First(colVariables), {colvarVariableOne:"NEW VALUE"});

     

    One thing that can catch you out is that collection column types are set when the collection is initiated so set the default value to be of that type.  For example to create a datetime column use:

    ClearCollect(colVariables, {colvarHoliday:DateTimeValue("01/01/2000 00:00"});

     

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 Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard