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 / Update local variables...
Power Apps
Answered

Update local variables in a loop

(0) ShareShare
ReportReport
Posted on by 32

Hello all,

 

Setup:

I have a set of 5 local variables say v1,v2,...,v5

I have another global variable varNum that can take value from 1 to 5.

 

What I want to do:

If varNum is 3, I want to set first 3 local variables v1,v2,v3 to true. 

If varNum is 1, set v1 to true and so on. 

 

Algorithm:

 

array = [v1,v2,v3,v4,v5]
For v in (1 to varNum):
 UpdateContext({array[v]:true})

 

I tried:

 

ForAll(
 FirstN([v1,v2,v3,v4,v5],varNum),
 UpdateContext({ThisRecord:true})
);

 

of course, Lord Microsoft does not allow to use UpdateContext under ForAll. Nor there is any loop function. If you can suggest something similar, that would be great.

Categories:
I have the same question (0)
  • Verified answer
    LaurensM Profile Picture
    12,516 Moderator on at

    Hi @Random1232,

     

    Setting a variable in a loop is currently not possible. As an alternative solution you could adjust the true / false logic.

     

    Instead of having 5 variables that are either true / false, set 1 variable to the respective number. In your example this would be varNum. In the scenario where varNum would be 3 -> v1, v2 & v3 would return true. Replace those variable references with a condition that returns true/false depending on the value of varNum:

     

    //Instead of v1 use:
    varNum >= 1
    
    //Instead of v2 use:
    varNum >= 2
    
    //and so on...

     

    If this solves your question, would you be so kind as to accept it as a solution & give it a thumbs up.

    Thanks!

  • Random1232 Profile Picture
    32 on at

    Thanks!

     

    I cannot use the varNum for this purpose since it has dependencies. That's why I was using local variable. But this gave me an idea to clone the varNum using OnVisible property of screen. 

    UpdateContext({lvarNum:varNum})

    Then I used this local variable lvarNum as you mentioned. This way I can change the local variable without affecting the global one.

     

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 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard