web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Use ForAll to iterate ...
Power Apps
Unanswered

Use ForAll to iterate a gallery, requiring a Set(Var) inside the ForAll Loop

(0) ShareShare
ReportReport
Posted on by 48

 

Background: this is in support of a searchable database for a non-profit's catalog of rare books, so getting searchable keywords over 1000's of books would be a big job manually. I also want to prove that PowerApps is up to the challenge for the data entry side this application.

 

Narrative: Using AI Keyword extraction to pull keywords from a title and a description of each item. The sample set has 100 items. The full catalog will have several thousand.

 

I can't find a viable way to implement this requirement because UpdateContext() and Set() are not allowed inside a ForAll loop. I need to process each item in a gallery, and setting a variable in each step is critical to that. Catch 22.

 

The Partial Code:

 

 

 

 

Set(
 ExtractedPhrases,
 'Key phrase extraction'.Predict(
 strPublicationTitle.Text,
 {Language: "en"}
 ).Phrases
);
IfError(
 ExtractedPhrases,
 Notify(
 FirstError.Message,
 NotificationType.Error
 )
);
IsError(
 ForAll(
 glryKeyWordExtraction.AllItems,
 If(
 ThisRecord.Phrase <> "Missing" && ThisRecord.Phrase <> "the",
 Patch(
 tblPublicationKeyWord,
 Defaults(tblPublicationKeyWord),
 {
 PublicationID: Value(intPublicationID.Text),
 KeyWord: ThisRecord.Phrase
 }
 )
 )
 )
);

 

 

 

 

 

So far, the workarounds I've seen don't support this specific scenario. I can process one item at a time, using OnSelect for that selected item in the gallery, but that means clicking a button potentially 1000's of times....

 

Is there any way to accomplish this? I've seen suggestions that involve a single column collection for example but I can't seem to get my head around how to incorporate it here.

Ideally, there would be a way to wrap the code above in ForAll(glryKeyWords). If that's not supported, maybe a Flow?

 

 

Thanks in advance.

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

    Hi @gpgeorge ,

     

    Setting a variable within a ForAll function is not supported within PowerApps currently. 

     

    As an alternative solution, you could use the timer control instead.

     

    You could use the control's Repeat property to control the number of cycles and use the OnTimerEnd property to to the set.

     

    Best Regards,

    Bof

     

     

  • gpgeorge Profile Picture
    48 on at

    The timer control? Okay, that would repeat the process, but how does it move from item to item in the gallery?

  • v-bofeng-msft Profile Picture
    Microsoft Employee on at

    Hi @gpgeorge ,

     

    You could create a variable and set it's value to 1. And use index(Datasource,VariableName) to get the current item in the loop. On timerend Set(VariableName,VariableName+1)

     

    Best Rgards,

    Bof

  • gpgeorge Profile Picture
    48 on at

    Thank you. To be honest, other factors in this app have taken priority and I haven't had time to go back and experiment with this suggestion. I will let you know when I've had time to do it.

     

    To be honest, this still relies on looping the data source and setting a variable, which seem to be the heart of the problem in the first place and where and how to use the timer is vague. 

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 325 Most Valuable Professional

#2
11manish Profile Picture

11manish 165

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 88 Super User 2026 Season 1

Last 30 days Overall leaderboard