Use a Dynamic URL to Filter a Dataset

667
0
11-22-2023 10:56 AM
JeffreyThompson2
MVP Regular Contributor
1 0 667

The following is copied from this post by @Shen_Zhang. This is my quick summary of the method.

  1. Create an Experience that does whatever you want it to do.
  2. Create a second Experience that is just an Embed widget.
  3. Stuff the first Experience into the second Experience.

Filters set in the data source tab in experience builder will be applied automatically, any further filters made from URL parameters will not replace but added to the current filter. However, it is possible to embed app URL with data_filter parameter to an embed widget. Users can neither see filters applied nor modify them. 

If you would like to make the embedded app to be more flexible, try a dynamic URL - you can replace any value you were using and pass URL parameters from the app URL to the Embed widget at run time to control what appears in the embedded contents. Here's what I tried to do with my configuration:

1. Create a new app and add an Embed widget with a map and a table

2. Copy and paste my app with a filter (here I use dsId:OID<20 as an example). Save the new app, append &exampleParam= to the end of app URL, and refresh the app

JeffreyThompson2_0-1700678697236.png

 

3. From Embed widget setting, you will see exampleParam in URL info. It can be added to the embedded URL by clicking on it. You can replace any content with {appURL.search.exampleParam}. Let's say we replace value "20" - now the filter changes to 

data_filter=dataSource_3-Feature_NAD1983_8510:OID%3C{appURL.search.exampleParam}

 4. Now save the app, publish and view the app. The app launches with no data in it (as the SQL expression in the Embed widget is incomplete and invalid)

JeffreyThompson2_1-1700678697292.png

 

5. Add ?exampleParam=20 to the URL. Now the app displays with the corresponding filter applied. 

JeffreyThompson2_2-1700678697297.png

 

I think this might be helpful as you could customize the parameter name (add multiple parameters if you want), also it gives you the flexibility to control what appears in the app to save some trouble. When deleting the parameter the users will only get an empty app - but if they managed to figure out what it is for (like setting a huge value in my case above), they may still able to see the whole dataset.

About the Author
A frequently confused rock-hound that writes ugly, but usually functional code.