Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Unanswered

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

(0) ShareShare
ReportReport
Posted on by 26

 

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:
  • gpgeorge Profile Picture
    26 on at
    Re: Use ForAll to iterate a gallery, requiring a Set(Var) inside the ForAll Loop

    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. 

  • v-bofeng-msft Profile Picture
    on at
    Re: Use ForAll to iterate a gallery, requiring a Set(Var) inside the ForAll Loop

    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
    26 on at
    Re: Use ForAll to iterate a gallery, requiring a Set(Var) inside the ForAll Loop

    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
    on at
    Re: Use ForAll to iterate a gallery, requiring a Set(Var) inside the ForAll Loop

    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

     

     

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,708 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,030 Most Valuable Professional

Leaderboard