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

Patch using ThisItem works in one case and doesn't in another, what gives?

Hey everyone... I'm using a Patch statement as simple as this below and it works fine.

 

Patch(QuestionPool,ThisItem,{Loaded: 0});

 

But in the same formula, I'm also trying to do another Patch and it's not working.

 

Patch(TempQuestions, ThisItem,{Delete: 1});

 

Why would one work and the other not work in the same formula? I've attached an image of the issue as well. 

1 ACCEPTED SOLUTION

Accepted Solutions

@krickard 

I just noticed that we missed an important fact.  Your PATCH statements are referencing 2 different datasources.

 

Patch(QuestionPool,ThisItem,{Loaded: 0});

Patch(TempQuestions, ThisItem,{Delete: 1});

 

Your PATCH is likely failing because TempQuestions is not the datasource for the Gallery.  Therefore we cannot reference it with ThisItem.

 

Suppose each question has a unique identifier called ID.  We could find the matching ID between QuestionPool and TempQuestions like this.

 

Patch(TempQuestions, LookUp(TempQuestion, ID=ThisItem.ID),{Delete: 1});

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

9 REPLIES 9
krickard
Helper III
Helper III

The strange thing is, the one that's not working is showing an error for a column that is not even being called in the formula nor is that column even in the referenced tables. 

@krickard 

It is weird that you are getting an error about a column that is not even being referenced.

 

As a first step in problem solving, suggest you cut + paste all of this code into Notepad temporarily.  Then write out that first PATCH function in the editor once again.  That way we can eliminate the problem as being a bug with the PowerApps formula bar error detection.

 

Also, suggest you open + close the app to see if it fixes the problem.  Its worked for me before when there is no obvious problem with my code 🙂

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Is detele the name of your column? That seems like a reserved word

@eka24
‘Delete’ can be used as a column name in SharePoint without any issue. Just trying to be helpful...

Thanks @mdevaney

@mdevaney 

 

I did as you suggested and kept just the first patch statement in there and it still has the same error. 

 

It's as if "ThisItem" is somehow artificially attached to the wrong column reference in the gallery. I have seen some funkiness with using OneDrive and Excel as the data source in PA before, just a few weeks ago. In that case, I had added a column in the middle of an existing data table and it started showing phantom errors on things that had previously been working. In a way I guess I've done something similar this time as well.  

 

This "Delete" column is new and I did the same thing, added a column to an existing Excel tab that was already in use by this PA app. Now I see phantom errors, even after refreshing the PA data source. The difference this time I guess is that the error is in a formula that directly uses the new column as opposed to last time were the phantom errors started occurring on formulas that were previously working and I had not changed them after adding the new column in Excel.  The way I fixed it the first time was to recreate the Excel workbook from scratch so I could add the new column from the start and also restore the PA app to a version that it was last working. Then build all the lost changes again in PA. 

 

I'm wondering if PA can't handle adding new columns in this scenario.  

@krickard 

I just noticed that we missed an important fact.  Your PATCH statements are referencing 2 different datasources.

 

Patch(QuestionPool,ThisItem,{Loaded: 0});

Patch(TempQuestions, ThisItem,{Delete: 1});

 

Your PATCH is likely failing because TempQuestions is not the datasource for the Gallery.  Therefore we cannot reference it with ThisItem.

 

Suppose each question has a unique identifier called ID.  We could find the matching ID between QuestionPool and TempQuestions like this.

 

Patch(TempQuestions, LookUp(TempQuestion, ID=ThisItem.ID),{Delete: 1});

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

@mdevaney 

 

I modified the code like this and it works now. Thanks for the help. 

 

Patch(TempQuestions, LookUp(TempQuestions, QuestionText = ThisItem.Question),{Delete: 1});

Now just have to get this bolded part working. I'll create another post for this one. 

 

Patch(TempQuestions, LookUp(TempQuestions, QuestionText = ThisItem.Question),{Delete: 1}); ForAll(TempQuestions, Patch(TempOptions, Filter(TempOptions, QID = TempQuestions.QID && TempQuestions.Delete = 1),{Delete: 1})); Remove(TempQuestions,Filter(TempQuestions, Delete > 0)); Remove(TempOptions,Filter(TempOptions, Delete > 0)); Patch(QuestionPool,ThisItem,{Loaded: 0});

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (39,402)