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 / Issue with Using Set a...
Power Apps
Answered

Issue with Using Set and ForAll in the OnSelect Event of a Button in Power Apps

(0) ShareShare
ReportReport
Posted on by 12

Hello everyone,

I’m encountering an issue in my Power Apps application when I try to execute both a Set() function and a ForAll() loop in the same OnSelect action of a button.

Context:

  • Page 1: The user selects a DropDown1 and a DropDown2, then fills in numbers for each TextInput in a Gallery1. Upon clicking a ā€œConfirmā€ button, the data is added to a Dataverse table using ForAll() and Patch().
  • Page 3: I want to display the data from the Gallery1 on Page 1 to allow the user to edit the entered Numbers. I’m trying to use the Set() function in OnSelect to store the gallery data in a global variable.

However, when I combine both functions (Set() to store the data and ForAll() to save the data to the Dataverse), I get errors.

Here’s the code I’m trying to execute:

 
PowerApps
Set(LastGalleryData; Gallery1.AllItems)
&
ForAll(Gallery1.AllItems; Patch(ETP_CAP_AAF; Defaults(ETP_CAP_AAF);{Site: Dropdown_BU.Selected.Value; Atelier: Dropdown_Atelier.Selected.Value; CAP: CAP.Text; Date: DatePicker.SelectedDate; 'Nombre d''ETP': Value(TextInput.Text); 'Date de crƩation de la ligne': Now(); 'Date de modification': Now()}))

What I’ve tried:

  • If I run the Set() code alone, it works perfectly.
  • If I run the ForAll() code alone, it also works.
  • The problem seems to only arise when I try to combine both actions in the same OnSelect.

Is there a specific way to execute both Set() and ForAll() in the same event? Or is there an alternative method for storing the gallery data while simultaneously patching it into the Dataverse?

Thanks in advance for your help!

I have the same question (0)
  • Verified answer
    Nandit Profile Picture
    1,568 Moderator on at
     
    Can you please try ";" and ";;" instead of "&" between the Set and ForAll statements? Looks like it requires different syntax based on Locale.
    Also, can you try saving the Gallery items in a collection instead? - 
     
    ClearCollect(LastGalleryData; Gallery1.AllItems)
    ;;
    ForAll(Gallery1.AllItems; Patch(ETP_CAP_AAF; Defaults(ETP_CAP_AAF);{Site: Dropdown_BU.Selected.Value; Atelier: Dropdown_Atelier.Selected.Value; CAP: CAP.Text; Date: DatePicker.SelectedDate; 'Nombre d''ETP': Value(TextInput.Text);
    'Date de crƩation de la ligne': Now(); 'Date de modification': Now()}))
    Hope this helps. 
     
    Kind regards, 
    Nandit
     
    If this answers your query, please mark this response as the answer.
    If its helpful, please leave a like. Thanks!
     

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 483

#2
WarrenBelz Profile Picture

WarrenBelz 399 Most Valuable Professional

#3
11manish Profile Picture

11manish 327

Last 30 days Overall leaderboard