You can automatically populate filters in your custom JS queries and dashboards by adding special tags.
Repositories, Teams, and Group By Filters
Image without caption
Date Filter
Image without caption

Javascript Example

javascript
begin_date = {begin_date} end_date = {end_date} repository_id = {repository_id} team_id = {team_id} time_period_group_by_id = {time_period_group_by_id} should_include_date_filter = begin_date && end_date date_filter = sql`AND external_merged_at >= ${begin_date} AND external_merged_at < ${end_date}` should_include_repository_filter= !!repository_id repository_filter = sql`AND repository_id = ${repository_id}` should_include_team_filter= !!team_id team_filter = sql`AND contributor_parent_teams.team_id = ${team_id}` prsMerged = await sql`SELECT date_trunc(${time_period_group_by_id}, external_merged_at) as Period, COUNT(*) as number_of_prs_merged FROM pull_requests INNER JOIN repositories ON pull_requests.repository_id = repositories.id INNER JOIN contributors ON pull_requests.contributor_id = contributors.id INNER JOIN contributor_parents ON contributor_parents.id = contributors.contributor_parent_id ${should_include_team_filter ? sql`INNER JOIN contributor_parent_teams ON contributor_parent_teams.contributor_parent_id = contributor_parents.id` : sql``} where 1=1 AND external_merged_at IS NOT null AND repositories.aasm_state='active' ${should_include_date_filter ? date_filter : sql``} ${should_include_repository_filter ? repository_filter : sql``} ${should_include_team_filter ? team_filter : sql``} GROUP BY PERIOD ORDER BY PERIOD` return addTrendline(prsMerged);
Note: Only officially supports the JS queries. It can work with raw SQL as well, but handling the edge cases of the filters not being selected is harder to accomplish.