Using dashboard timeframes in your data streams

If you’re using a configurable data stream where you need to provide a query, it’s pretty common that you’d want to make your data responsive to the dashboard’s timeframe picker. SquaredUp lets you reference the timeframe options (along with other things), using Mustache.

Here are the options…

{{timeframe.start}}        >> "2024-03-01T00:00:00.000Z"
{{timeframe.end}}          >> "2024-04-01T00:00:00.000Z"
{{timeframe.unixStart}}    >> 1709251200
{{timeframe.unixEnd}}      >> 1711929600
{{timeframe.enum}}         >> "thisMonth"
{{timeframe.interval}}     >> "PT12H"

In most cases, you’re probably looking for a combo of {{timeframe.start}} and {{timeframe.end}}, or the unix equivalents. Most APIs and query languages will be happy with those.

As a couple of examples, here’s a Salesforce SOQL query that gets Tasks…

SELECT
    Description,
    CloseDate
FROM
    Task

And with timeframe…

SELECT
    Description,
    CloseDate
FROM
    Task
WHERE
    CloseDate > {{timeframe.start}}
    AND CloseDate < {{timeframe.end}}

With that addition to the query, whenever your dashboard viewer changes the timeframe at the top of the page, the query will be re-run with the new values.

In this scenario, Salesforce would receive the following…

SELECT
    Description,
    CloseDate
FROM
    Task
WHERE
    CloseDate > "2024-03-01T00:00:00.000Z"
   AND CloseDate < "2024-04-01T00:00:00.000Z"
1 Like