Hi Squiz Folk
I’m trying to use an asset listing page to populate a dropdown list based on a metadata value/s via custom grouping. Asset type to list => Calendar Event
The issue is that its populating everything but I need to only populate (dynamically update) values past or equal to today’s date?
PS - I know the below example is wrong but just wanted to show what I’m trying to do.
Grouping by metadata values - trying to create a dropdown values based on “region” (metadata) on future events not in the past. Easy using a event search asset but haven’t tried what you have suggested.
Depending on the number of events you have, the best bet is probably to spit out all events into an array, filter by date and then find unique values for region.
Asset listing (with no grouping) with json output of the necessary attributes for your events
eg. {“id”:"%asset_assetid%",“region”:"%asset_metadata_Region%",“datetime”:"%event_start_datetime%"},
Using ssjs (XXX is ID of asset listing)
<script runat="server">
var events = %globals_asset_contents:XXX%;
// filter array on date comparison, return true if event is in future
var regions = events.filter(function(o){ ... })
// reduce the array to region string
.map(function(o){ return o.region})
// and find unique values
.filter(function(x,i,a) { return a.indexOf(x) == i});
And then print an option tag for each value in regions.
I omitted the date test function for brevity.
Actually, I’d imagine you could use a search page instead of an asset listing to filter the events. If so, then you would only need to output the region and use the last line to filter uniques.