cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Cscox21
Regular 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

4 REPLIES 4
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]', 
         ThisItem.Expanded=true
      )
   ), 
   {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. 

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.

Top Solution Authors
Top Kudoed Authors
Users online (73,316)