cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Reveal/hide menu trees with StartsWith() within a collection patch

I've been trying to use the following code to modify an existing collection, 'Col_Media_AirportData', so that it changes the value of 'ID' from 'false' to 'true' when the associated gallery item is selected. The aim is to show/hide subelements/subitems that share the element ID, eg:

 

1.1 should reveal 1.1.1, 1.1.2 etc

2.1 should reveal 2.1.1, 2.1.2 etc

 

I based the code on an online example by 6FootMedia LLC. The result of the original code (in green, below) was that the patch altered the ID value for anything containing the parent code, eg 1.1, eg 2.1.1. This understandably caused issues! The purpose of the new code is to change the value of 'ID' for the 'child' subelements that sit beneath the 'parent' elements. So 1.1, when selected, should reveal/hide 1.1.1, 1.1.2 etc.  Hence the idea of the 'startswith' condition is to force PowerApps to check that the item begins with the parent directory, and only reveals/hides those items. 

 

However, this does not work. The code shows no errors, but does not appear to be changing the values. What can I change to fix this? 

 

 

 

Select(Parent);
Patch(
    Col_Media_AirportData,
    Filter(
        Col_Media_AirportData,
       StartsWith(ThisItem.ID,ID)  //formerly ThisItem.ID in ID

&& ID <> ThisItem.ID ), ForAll( Filter( Col_Media_AirportData, StartsWith( ThisItem.ID, ID //formerly ThisItem.ID in ID ) in ID && ID <> ThisItem.ID ), If( ThisItem.Expanded, {Shown: false}, {Shown: true} ) ) ); Patch( Col_Media_AirportData, Filter( Col_Media_AirportData, ThisItem.ID = ID ), ForAll( Filter( Col_Media_AirportData, ThisItem.ID = ID ), {Expanded: !Expanded} ) )

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-siky-msft
Community Support
Community Support

Hi @Anonymous ,

 

Do you want to filter out all items that items' ID start with thisitem ID in you first part of codes.

I find something strange with your StartsWith function. The syntax is StartsWith( Text, StartText ), so the first parameter should be column you want to test, the second parameter is the text to search for at the beginning of column.

So could you modify your two StartsWith functions as StartsWith(ID, ThisItem.ID) in you codes and try again to check if your issue is fixed.

 

Best regards,

Sik

 

View solution in original post

7 REPLIES 7
v-siky-msft
Community Support
Community Support

Hi @Anonymous ,

 

Do you want to filter out all items that items' ID start with thisitem ID in you first part of codes.

I find something strange with your StartsWith function. The syntax is StartsWith( Text, StartText ), so the first parameter should be column you want to test, the second parameter is the text to search for at the beginning of column.

So could you modify your two StartsWith functions as StartsWith(ID, ThisItem.ID) in you codes and try again to check if your issue is fixed.

 

Best regards,

Sik

 

View solution in original post

Anonymous
Not applicable

@v-siky-msft Fixed! After dealing with a few further typos, the code worked fine. Thank you very much for pointing out this silly error!

mdevaney
Super User
Super User

@Anonymous 

I am curious, what did you final product look like for the Reveal/Hide menu trees?  If you are able to share some screenshots I think it would be neat.

 

Hi @Anonymous ,

 

If that post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly.

 

Best regards,

Sik

Anonymous
Not applicable

Apologies Sik, I thought I had done that. I’ve checked and I’ve definitely clicked ‘accept as solution’ now-thank you once again.
Anonymous
Not applicable

@mdevaney @v-siky-msft It's a work in progress, but here's what I've got so far. See attached.

 

 

@Anonymous 

That drill down gallery you made is very cool.  Maybe you could do a Community Blog article on it once you've got it perfected.

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,545)