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 / Second and third state...
Power Apps
Answered

Second and third statements not being executed when my button is clicked.

(0) ShareShare
ReportReport
Posted on by 330

In the OnSelect of my button, I have three statements I am trying to run. Each of these three statements work independently, and I get my desired results. However, when I put them together, only the first one runs....meaning the second Patch statement + Navigate do not get executed. If I take out the first Patch statement, the other two run just fine....so the second Patch runs and the Navigate runs as well. So for some odd reason, the first Patch statement is preventing the others from being executed. What could be causing this? 

Patch(
	list1, 
	ForAll(
		Gallery1.AllItems, 
		If(
			chkBox.Value = true, 
			{
				Col1: label.Text, 
				col2: label2.Text,
				User: {
					'@data.type': "@Microsoft.Azure.Connections.SharePoint.SPLitExpandedUser", 
					Claims: labelClaims.Text, 
					DisplayName:labelNme.Txt, 
					Department: labelDept.Text, 
					Email:labelEmail.Text, 
					JobTitle: "", 
					Picture: ""
				}
			}
		)
	)
);

ForAll(
	Filter(
		Gallery1.AllItems, 
		chkBox.Value=false
	) As _myData, 
	Patch(
		list2, 
		LookUp(
			list2, 
			ID=_myData.ID
		), 
		{myChoiceCol: {Value: "Choice3"}}
	)
);

Navigate(SuccessScreen);

 

Has anyone ran into this issue?  How was it resolved?

Categories:
  • CU18061035-1 Profile Picture
    Microsoft Employee on at

    hey @Spawn10 

     

    please try this:

    // Set a context variable to false initially
    UpdateContext({IsFirstPatchComplete: false});
    
    // First Patch Statement
    Patch(
     list1, 
     ForAll(
     Gallery1.AllItems, 
     If(
     chkBox.Value = true, 
     {
     Col1: label.Text, 
     col2: label2.Text,
     User: {
     '@data.type': "@Microsoft.Azure.Connections.SharePoint.SPLitExpandedUser", 
     Claims: labelClaims.Text, 
     DisplayName: labelNme.Text, 
     Department: labelDept.Text, 
     Email: labelEmail.Text, 
     JobTitle: "", 
     Picture: ""
     }
     }
     )
     )
    );
    
    // After the first Patch, update the context variable
    UpdateContext({IsFirstPatchComplete: true});
    
    // Check if the first Patch is completed
    If(
     IsFirstPatchComplete,
    
     // Second Patch Statement
     ForAll(
     Filter(
     Gallery1.AllItems, 
     chkBox.Value=false
     ) As _myData, 
     Patch(
     list2, 
     LookUp(
     list2, 
     ID=_myData.ID
     ), 
     {myChoiceCol: {Value: "Choice3"}}
     )
     );
    
     // Navigate to Success Screen
     Navigate(SuccessScreen);
    );

     

    Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.



    Greetings

  • Spawn10 Profile Picture
    330 on at

    Thank you so much for this suggestion. However, this is resetting the value of my checkbox, which prevents the second Patch from doing what it is intended to do. Is there a way to perform this, without resetting the value of the checkbox?

  • Verified answer
    CU18061035-1 Profile Picture
    Microsoft Employee on at

    The issue you're encountering seems to be related to how the checkbox values are being managed in your Power Apps canvas app. When you perform operations like Patch, it can sometimes lead to a refresh of the controls (like checkboxes) on the screen, which might reset their values.

     

    Try this instead pls:

     

    // Create a temporary collection to store the state of gallery items
    ClearCollect(tempGalleryItems, Gallery1.AllItems);
    
    // First Patch Statement
    ForAll(
     tempGalleryItems,
     If(
     chkBox.Value = true,
     Patch(
     list1, 
     Defaults(list1), 
     {
     Col1: label.Text, 
     col2: label2.Text,
     User: {
     '@data.type': "@Microsoft.Azure.Connections.SharePoint.SPLitExpandedUser", 
     Claims: labelClaims.Text, 
     DisplayName: labelNme.Text, 
     Department: labelDept.Text, 
     Email: labelEmail.Text, 
     JobTitle: "", 
     Picture: ""
     }
     }
     )
     )
    );
    
    // Check if the first Patch is completed using a variable
    Set(IsFirstPatchComplete, true);
    
    If(
     IsFirstPatchComplete,
    
     // Second Patch Statement
     ForAll(
     Filter(
     tempGalleryItems, 
     chkBox.Value=false
     ) As _myData, 
     Patch(
     list2, 
     LookUp(
     list2, 
     ID=_myData.ID
     ), 
     {myChoiceCol: {Value: "Choice3"}}
     )
     );
    
     // Navigate to Success Screen
     Navigate(SuccessScreen);
    );

     

    This approach should prevent the checkbox values from being reset during the patch operations.

  • Spawn10 Profile Picture
    330 on at

    Thanks a million for helping me resolve this...cheers

  • CU18061035-1 Profile Picture
    Microsoft Employee on at

    great that it worked, always happy to help 😉

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 243 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 204 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 122

Last 30 days Overall leaderboard