=with( /*Set facet filter value. If none, get "all" from web service*/ local!filterValue: if( not(isnull(ri!query.'logicalExpression|filter|search')), if( runtimetypeof(ri!query.'logicalExpression|filter|search')='type!{http://www.appian.com/ae/types/2009}QueryFilter', ri!query.'logicalExpression|filter|search'.value, "all" ), "all" ), /*Set search query to null if nothing present*/ local!searchTerm: if( not(isnull(ri!query.'logicalExpression|filter|search')), if( runtimetypeof(ri!query.'logicalExpression|filter|search')='type!{http://www.appian.com/ae/types/2009}Search', ri!query.'logicalExpression|filter|search'.searchQuery, null ), null ), /*Call web service using filterValue*/ local!services: xpathsnippet( "http://www.nyc.gov/portal/apps/311_contentapi/services/" & local!filterValue & ".xml", "/services/service[position() >= 1 and position() < 101]"), /* Populate list of titles to search on*/ local!serviceTitles: apply(rule!NYC311ServiceExtractTitle, local!services), /*Filter results if searchTerm is present*/ local!filteredServiceIndicies: if( not(isnull(local!searchTerm)), where(search(local!searchTerm, local!serviceTitles)), enumerate(length(local!services))+1 ), /*Create array of filtered services to use for list view and identifiers*/ local!filteredServices: index(local!services, local!filteredServiceIndicies), /*Populate List View Items for filtered Services*/ local!servicesListView: apply(rule!NYC311ServiceLVI, local!filteredServices), /*Populate Identifiers for filtered Services*/ local!servicesIdentifiers: apply(rule!NYC311ServiceExtractId, local!filteredServices), /*Create List View*/ 'type!{http://www.appian.com/ae/types/2009}ListView'( dataSubset: 'type!{http://www.appian.com/ae/types/2009}ListViewDataSubset'( startIndex: 1, batchSize: count(local!servicesListView), totalCount: count(local!servicesListView), data: local!servicesListView, identifiers: local!servicesIdentifiers ), /*Create defined Facets*/ facets: 'type!{http://www.appian.com/ae/types/2009}Facet'( name:"Category", options:{ 'type!{http://www.appian.com/ae/types/2009}FacetOption'( id:1, name:"Environment and Sanitation", filter:'type!{http://www.appian.com/ae/types/2009}QueryFilter'( field:"category", operator:"=", value:"Environment%20and%20Sanitation" ) ), 'type!{http://www.appian.com/ae/types/2009}FacetOption'( id:2, name:"Education and Employment", filter:'type!{http://www.appian.com/ae/types/2009}QueryFilter'( field:"category", operator:"=", value:"Education%20and%20Employment" ) ), 'type!{http://www.appian.com/ae/types/2009}FacetOption'( id:3, name:"Business and Finance", filter:'type!{http://www.appian.com/ae/types/2009}QueryFilter'( field:"category", operator:"=", value:"Business%20and%20Finance" ) ), 'type!{http://www.appian.com/ae/types/2009}FacetOption'( id:4, name:"Social Services", filter:'type!{http://www.appian.com/ae/types/2009}QueryFilter'( field:"category", operator:"=", value:"Social%20Services" ) ), 'type!{http://www.appian.com/ae/types/2009}FacetOption'( id:5, name:"Health and Medicine", filter:'type!{http://www.appian.com/ae/types/2009}QueryFilter'( field:"category", operator:"=", value:"Health%20and%20Medicine" ) ), 'type!{http://www.appian.com/ae/types/2009}FacetOption'( id:6, name:"Public Safety and Law", filter:'type!{http://www.appian.com/ae/types/2009}QueryFilter'( field:"category", operator:"=", value:"Public%20Safety%20and%20Law" ) ), 'type!{http://www.appian.com/ae/types/2009}FacetOption'( id:7, name:"Government and Civil Services", filter:'type!{http://www.appian.com/ae/types/2009}QueryFilter'( field:"category", operator:"=", value:"Government%20and%20Civil%20Services" ) ) } ) ) )