cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Cscox21
Frequent Visitor

Convert Patch function To UpdateIf

I have been following a Tree Hierarchy video (https://www.youtube.com/watch?v=qJv8IqqL01A&t=575s) to get some Collapsible/Expandable functionality but due to how the data is structured, we cannot use the Patch function. I have been led to the UpdateIf function and am struggling to figure it out. 

 

Here is the code that the video uses for Patch: 

Patch(
    TreeItems,
        Filter(TreeItems,ThisItem.Treepath in Treepath && Treepath<>ThisItem.Treepath),
        ForAll(Filter(TreeItems,ThisItem.Treepath in Treepath&&Treepath<>ThisItem.Treepath),
        If(ThisItem.Expanded,{Shown: false },{Shown: true }))
);
// Patch the parent node to indicate if it is expanded/collapsed
Patch(
    TreeItems,
        Filter(TreeItems,ThisItem.Treepath=Treepath),
        ForAll(Filter(TreeItems,ThisItem.Treepath=Treepath),
        {Expanded:!Expanded})
)

 

Here is my starting point for using the UpdateIf:

UpdateIf(AllRecords_values, (Filter('[dbo].[lut_Skills]', ThisItem.Expanded=true)), {Expanded:!Expanded});

 

The error i am getting is either Invalid Arguments or Expecting a boolean value if i change the last part to ThisItem.Expanded:! ThisItem.Expanded. 

 

Any tips/pointers/etc. is appreciated. I am not tied to any one function, I am just trying to get a tree hierarchy functionality. 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions

@Cscox21 ,

It seems to be multiple lines of text (I do not use SQL in Power Apps).

The issue is clearly this field due to the incompatible type error your are getting. You need to convert it into the field type that the query expects.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

14 REPLIES 14
WarrenBelz
Super User III
Super User III

Hi @Cscox21 ,

I will only deal with the UpdateIf() here - but I am also a bit confused as to what you are doing with the Patches.

UpdateIf(
   AllRecords_values,
   (
      Filter(
         '[dbo].[lut_Skills]', 
         Expanded
      )
   ), 
   {Expanded:!Expanded}
);

 

 

The fundamental issues I see are two - you are updating records in AllRecords_value, but are getting the matching records from '[dbo].[lut_Skills]' with no reference to what "joins" them.

Also the matching syntax of an Update If is not in {} brackets. 

Taking a bit of a guess at what you structure is (and Patch is much easier here)

With(
   {
      wExpand:
      Filter(
         '[dbo].[lut_Skills]', 
         Expanded
      )
   },
   ForAll(
      wExpand,   
      Patch(
         AllRecords_values,
         {MatchingField:wExpand.MatchingField},
         {Expanded:!Expanded}
      )
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

WarrenBelz
Super User III
Super User III

Hi @Cscox21 ,

Just checking if you got the result you were looking for on this thread. Happy to help further if not.

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

My apologies, i got thrown an emergency project late last week that is due tomorrow so i havent had a chance to try your proposed solution. I will get back to you tomorrow or the next day after i have tried it, thank you for following up!

Hey Warren, 

I am finally able to get back to this task. I have typed in the code you provided and received the following errors: 

The function Filter has invalid arguments as well as the Patch function having invalid arguments. I then copied and pasted what you provided to see if i mistyped and i am getting the same errors. This code is on the OnSelect function for an Image component. 

@Cscox21 ,

As I mentioned, I was simply using your code, so any reference errors will still be there. 

I assume you replaced MatchingField with your actual matching field names.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

So obviously i know very little and my C# knowledge isnt transferring well. 

I have input your text and am trying to use the "MatchingField" you mention with Treepath and the function wants a Text field as an argument and not the column. 

 

With(
   {
      wExpand:
      Filter(
         '[dbo].[lut_Skills]', 
         Expanded
      )
   },
   ForAll(
      wExpand,   
      Patch(
         AllRecords_values,
         {Treepath: wExpand.Treepath},
         {Expanded:!Expanded}
      )
   )
)

How can i convert the Treepath to a text field?  

@Cscox21 ,

What type of field is TreePath?

It appears to be a column name for some of my collections. But ThisItem.Treepath is coming up as a Text data type. The problem with this is i am still getting an error with variations of this: 

With(
   {
      wExpand:
      Filter(
         '[dbo].[lut_Skills]', 
         Expanded
      )
   },
   ForAll(
      wExpand,   
      Patch(
         AllRecords_values,
         {ThisItem.Treepath: wExpand.ThisItem.Treepath},
         {Expanded:!Expanded}
      )
   )
)

I have tried moving the ThisItem before the wExpand, replacing the wExpand, and maybe a couple more and still errors. 

@Cscox21 ,

If it is Text (actual single line of Text) - I assume you are using SharePoint - then this should work

With(
   {
      wExpand:
      Filter(
         '[dbo].[lut_Skills]', 
         Expanded
      )
   },
   ForAll(
      wExpand,   
      Patch(
         AllRecords_values,
         {TreePath:wExpand.TreePath},
         {Expanded:!Expanded}
      )
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

 

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 Winner Announcement

Please join us on Wednesday, July 21st at 8a PDT. We will be announcing the Winners of the Demo Extravaganza!

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (1,681)