cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jacktransform
Helper III
Helper III

Can't Patch Twice?

Hello all!

 

I'm running into an error with my Patch in my PowerApp. 

 

I have two data sources for my PowerApp, two entities in CDS, one a parent (ParentEntity) and the other a child (ChildEntity.) This app also has three screens.

 

In the first screen, there is a Gallery1 where you select a record from the parent entity (ParentEntity.) A selection of a record from ParentEntity takes you to the second screen.

 

On screen two you can create a new record for the child entity. In this new form, I have a card (not visible to the user) for the Lookup field to the parent entity, with the "DefaultSelectedItems" as Gallery1.Selected. This way, this new record in the child entity will be linked to the parent (Gallery1.Selected) when I save. On this screen I also have a save button, and the OnSelect property for that button looks something like this:

 

Patch([@ParentEntities], Gallery1.Selected, {'Is Logged?': 'Is Logged? (ParentEntities)'.Yes});
SubmitForm(NewChildEntityForm)
 
As you can see, when I save this new form for the new record in ChildEntity, I want to patch fields in ParentEntity, mainly a field of type Two Options that denotes whether or not the record in ParentEntity has been logged. (The creation of a new record in ChildEntity means that the record in ParentEntity it is associated to has been logged.)  This works great, and when I create this new record in ChildEntity, it patches the information I want into its parent in the ParentEntity, or in other words it patches information into the record I selected in the gallery on the first screen. 
 
The problem comes with the third screen. After clicking the save button, the user is taken to screen three, where he/she can view the form they just submitted. In other words, he/she views the new record in ChildEntity that they just created on screen two. On screen three, I also have a delete button, with its OnSelect property as something like this:
 
Patch([@ParentEntities], Gallery1.Selected, {'Is Logged?': 'Is Logged? (ParentEntities)'.No});
Remove([@ChildEntities], NewChildEntityForm.LastSubmit)
 
After clicking the delete button, the previously saved record in ChildEntity is deleted and removed from CDS, but my 'Is Logged?' field in my record in the ParentEntity is still "Yes" instead of "No."
 
Can anyone tell me what's the problem here? I want to say it's something wrong with Gallery1.Selected, and that after submitting the new form it clears whatever was previously held in that variable? I even tried the following for the second patch:
 
Patch([@ParentEntities], NewChildEntityForm.LastSubmit.ParentEntity, {'Is Logged?': 'Is Logged? (ParentEntities)'.No});
 
But still, no luck! If anyone is familiar with this problem, please let me know what you did to solve it.
 
Thanks!
 
 
 

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-siky-msft
Community Support
Community Support

Hi @jacktransform ,

 

I support your point of view that the issue is due to 'Gallery1.Selected'.

I would suggest you save the GUID field value of selected item from Gallery1 to a variable, and use LookUp() formula to retrieve that record. Please modify the codes as follows

 

Set(varSelectedID, ThisItem.GUIDField) //Gallery1.OnSelect

LookUp('Parent Entity', GUIDField=varSelectedID)  //DefaultSelectedItems of lookup field combobox

Patch([@ParentEntities], LookUp('Parent Entity', GUIDField=varSelectedID), {'Is Logged?': 'Is Logged? (ParentEntities)'.No}); //DeleteButton.OnSelect

 

Hope this helps.

Sik

View solution in original post

2 REPLIES 2
v-siky-msft
Community Support
Community Support

Hi @jacktransform ,

 

I support your point of view that the issue is due to 'Gallery1.Selected'.

I would suggest you save the GUID field value of selected item from Gallery1 to a variable, and use LookUp() formula to retrieve that record. Please modify the codes as follows

 

Set(varSelectedID, ThisItem.GUIDField) //Gallery1.OnSelect

LookUp('Parent Entity', GUIDField=varSelectedID)  //DefaultSelectedItems of lookup field combobox

Patch([@ParentEntities], LookUp('Parent Entity', GUIDField=varSelectedID), {'Is Logged?': 'Is Logged? (ParentEntities)'.No}); //DeleteButton.OnSelect

 

Hope this helps.

Sik

View solution in original post

Thanks, @v-siky-msft, that seemed to work!

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (2,264)