cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
bolandre92
Helper II
Helper II

How to reverse a Patch function to be able to erase

Hi, 

 

I am using the Patch function to write in a collections through a toggle (Oncheck), i would like to reverse (erase the row) that patch when users uncheck the Toggle. The current Patch function is as follows:

 

Patch(CPPayments, ThisItem, {APLCOMPROBANTE: IComprobante.Text, APLMONTO_TOTAL: Value(IMonto_Total.Text)})

 

Any help is very grateful. 

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @bolandre92 ,

Do you want to reverse a Patch function without removing the row from your collection?

 

If you want to reverse a Patch function without removing the row from your collection, I afraid that there is no direct way to achieve your needs.

 

According to the scenario that you mentioned, I think the RemoveIf function would be the direct solution. You could use the RemoveIf function to remove the corresponding row from your CPPayments collection. When you check the Toggle control inside your Gallery again, the Patch formula that you mentioned would be executed again to patch new entry into your CPPayments collection.

 

In addition, if you do not want to remove the item from your collection, you could consider add a column in your  CPPayments collection to store the "status" of the Toggle control. For example, you could consider add a "ToggleState" column into your CPPayments collection. Then bind it to a Gallery (set the Items property of a Gallery to this collection).

After that, modify the formula within the Oncheck property of the Toggle to following:

Patch(
      CPPayments,
      ThisItem,
      {
         APLCOMPROBANTE: IComprobante.Text, 
         APLMONTO_TOTAL: Value(IMonto_Total.Text),
         ToggleState: "Active"    // Modify formula here
      }
)

Set the OnUncheck property of the Toggle control to following:

Patch(
      CPPayments,
      ThisItem,
      {
         APLCOMPROBANTE: IComprobante.Text, 
         APLMONTO_TOTAL: Value(IMonto_Total.Text),
         ToggleState: "Inactive"       // Modify formula here
      }
)

Set the Default property of the Toggle control (Toggle1, inside your Gallery) to following:

If(
   ThisItem.ToggleState = "Active",
   true,
   false
)

 

Please consider take a try with above solution, then check if it could help in your scenario.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
KrishnaV
Super User III
Super User III

Hi @bolandre92 ,

 

try this:

Remove(CPPayments, ThisItem)

 
I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
Krishna
If this post helps you give a 👍 and if it solved your issue consider Accept it as the solution to help the other members find it more.


I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
KrishnaV
Business Applications MVP
Twitter | Linkedin | YouTube | GitHub
If this post helps you give a and if it solved your issue consider Accept it as the solution to help the other members / new members of the community.

Hi Krishna, 

 

It worked however it removed it from the entire collection. Is there any way to reverse the Patch and keep the record, just in case that the user considers to turn it on again. 

 

Thank you. 

v-xida-msft
Community Support
Community Support

Hi @bolandre92 ,

Do you want to reverse a Patch function without removing the row from your collection?

 

If you want to reverse a Patch function without removing the row from your collection, I afraid that there is no direct way to achieve your needs.

 

According to the scenario that you mentioned, I think the RemoveIf function would be the direct solution. You could use the RemoveIf function to remove the corresponding row from your CPPayments collection. When you check the Toggle control inside your Gallery again, the Patch formula that you mentioned would be executed again to patch new entry into your CPPayments collection.

 

In addition, if you do not want to remove the item from your collection, you could consider add a column in your  CPPayments collection to store the "status" of the Toggle control. For example, you could consider add a "ToggleState" column into your CPPayments collection. Then bind it to a Gallery (set the Items property of a Gallery to this collection).

After that, modify the formula within the Oncheck property of the Toggle to following:

Patch(
      CPPayments,
      ThisItem,
      {
         APLCOMPROBANTE: IComprobante.Text, 
         APLMONTO_TOTAL: Value(IMonto_Total.Text),
         ToggleState: "Active"    // Modify formula here
      }
)

Set the OnUncheck property of the Toggle control to following:

Patch(
      CPPayments,
      ThisItem,
      {
         APLCOMPROBANTE: IComprobante.Text, 
         APLMONTO_TOTAL: Value(IMonto_Total.Text),
         ToggleState: "Inactive"       // Modify formula here
      }
)

Set the Default property of the Toggle control (Toggle1, inside your Gallery) to following:

If(
   ThisItem.ToggleState = "Active",
   true,
   false
)

 

Please consider take a try with above solution, then check if it could help in your scenario.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Hi @bolandre92 ,

 

I totally agree with @v-xida-msft if you want the record to be in the collection you need to implement the behavior as soft add and soft delete with a flag. Please ensure that you validate the ToggleState flag while you are populating back to data source.

 

I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
Krishna
If this post helps you give a 👍 and if it solved your issue consider Accept it as the solution to help the other members find it more.


I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
KrishnaV
Business Applications MVP
Twitter | Linkedin | YouTube | GitHub
If this post helps you give a and if it solved your issue consider Accept it as the solution to help the other members / new members of the community.

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

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

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

Top Solution Authors
Top Kudoed Authors
Users online (53,766)