<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Hardcoding USQL Timeframe in Dynatrace Notebook Fails for Dynamic Grail Dashboards – Here’s How to Fix It in Real User Monitoring</title>
    <link>https://community.dynatrace.com/t5/Real-User-Monitoring/Hardcoding-USQL-Timeframe-in-Dynatrace-Notebook-Fails-for/m-p/291228#M7187</link>
    <description>&lt;P&gt;I can't help you with solving this exact issue but in general, DQL on top of user.events and user.sessions will offer direct ways to query the data and plot it. Including counting users etc. so it's not recommended to query via javascript code and USQL RUM data captured by Dynatrace.&lt;BR /&gt;for now, the new RUM experience is in public preview until January. In the meantime - if you're not part of the preview - explore within discover dynatrace - e.g. under&amp;nbsp;&lt;A href="https://wkf10640.apps.dynatrace.com/ui/apps/dynatrace.experience.vitals/" target="_blank"&gt;https://wkf10640.apps.dynatrace.com/ui/apps/dynatrace.experience.vitals/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 10 Dec 2025 11:56:45 GMT</pubDate>
    <dc:creator>paul_kapeller</dc:creator>
    <dc:date>2025-12-10T11:56:45Z</dc:date>
    <item>
      <title>Hardcoding USQL Timeframe in Dynatrace Notebook Fails for Dynamic Grail Dashboards - how to fix it?</title>
      <link>https://community.dynatrace.com/t5/Real-User-Monitoring/Hardcoding-USQL-Timeframe-in-Dynatrace-Notebook-Fails-for/m-p/273576#M6824</link>
      <description>&lt;P class=""&gt;&lt;FONT color="#000080"&gt;&lt;STRONG&gt;Hi Dynatrace Community,&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=""&gt;I wanted to share my experience with querying USQL in a Dynatrace Notebook using JavaScript to fetch Real User Monitoring (RUM) data for a Grail dashboard, as Grail doesn’t have built-in RUM metrics. My goal was to display the number of active users in a dashboard tile, but I encountered an issue with making the timeframe dynamic.&lt;/P&gt;
&lt;H3&gt;The Problem&lt;/H3&gt;
&lt;P class=""&gt;I used the following USQL query in a Notebook to count distinct users for my application, xxx:&lt;BR /&gt;&lt;BR /&gt;SELECT COUNT(DISTINCT userId)&lt;BR /&gt;FROM usersession&lt;BR /&gt;WHERE useraction.application = 'xxx'&lt;BR /&gt;AND userType = 'REAL_USER'&lt;BR /&gt;AND applicationType = 'MOBILE_APPLICATION'&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;DIV&gt;
&lt;P class=""&gt;Initially, I hardcoded the timeframe in my JavaScript code (e.g., using a default of the last 7 days or a specific date like March 25, 2025). While this worked to fetch the data, the tile was not dynamic when pinned to a Grail dashboard—it didn’t update when I changed the dashboard’s timeframe (e.g., to “Yesterday” or “Last 30 days”). The console log showed &lt;SPAN class=""&gt;Context object: { "$": null }&lt;/SPAN&gt;, indicating that the dashboard’s timeframe wasn’t being passed to the Notebook code.&lt;/P&gt;
&lt;P class=""&gt;Here’s an example of the hardcoded approach I tried:&lt;/P&gt;
&lt;/DIV&gt;
&lt;P class=""&gt;javascript&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;&lt;SPAN&gt;// Fallback to hardcoded timeframe (Yesterday: March 25, 2025)&lt;/SPAN&gt; &lt;SPAN&gt;console&lt;/SPAN&gt;&lt;SPAN&gt;.warn(&lt;/SPAN&gt;&lt;SPAN&gt;"Dashboard timeframe not available. Falling back to hardcoded timeframe (Yesterday)."&lt;/SPAN&gt;&lt;SPAN&gt;); &lt;/SPAN&gt;&lt;SPAN&gt;startTimestamp = &lt;/SPAN&gt;&lt;SPAN&gt;new&lt;/SPAN&gt; &lt;SPAN&gt;Date&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;"2025-03-25T00:00:00.000Z"&lt;/SPAN&gt;&lt;SPAN&gt;).getTime(); &lt;/SPAN&gt;&lt;SPAN&gt;endTimestamp = &lt;/SPAN&gt;&lt;SPAN&gt;new&lt;/SPAN&gt; &lt;SPAN&gt;Date&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;"2025-03-25T23:59:59.999Z"&lt;/SPAN&gt;&lt;SPAN&gt;).getTime();&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;
&lt;H3&gt;Why Hardcoding Doesn’t Work&lt;/H3&gt;
&lt;P class=""&gt;Hardcoding the timeframe means the tile is static and won’t reflect the dashboard’s selected timeframe. This approach is fine for testing but fails for dynamic dashboard integration, which is essential for real-time monitoring and reporting in Grail dashboards. For example, if the dashboard timeframe is set to “Last 30 days,” a hardcoded tile will still show data for the hardcoded date (e.g., March 25, 2025), leading to incorrect or outdated insights.&lt;/P&gt;
&lt;H3&gt;What I tried&lt;/H3&gt;
&lt;DIV&gt;To make the USQL query dynamic, I updated my JavaScript code to use the &lt;SPAN class=""&gt;context.timeframe&lt;/SPAN&gt; object, which contains the dashboard’s selected timeframe. The key is to check for &lt;SPAN class=""&gt;context.timeframe.start&lt;/SPAN&gt; and &lt;SPAN class=""&gt;context.timeframe.end&lt;/SPAN&gt; and use those values for the USQL query’s timeframe parameters. Here’s the relevant code snippet:&lt;/DIV&gt;
&lt;P class=""&gt;javscript code&lt;BR /&gt;let startTimestamp, endTimestamp;&lt;BR /&gt;if (context?.timeframe?.start &amp;amp;&amp;amp; context?.timeframe?.end) {&lt;BR /&gt;// Use the dashboard's timeframe (already in UTC milliseconds)&lt;BR /&gt;startTimestamp = context.timeframe.start;&lt;BR /&gt;endTimestamp = context.timeframe.end;&lt;BR /&gt;console.log("Using dashboard timeframe:", {&lt;BR /&gt;start: new Date(startTimestamp).toISOString(),&lt;BR /&gt;end: new Date(endTimestamp).toISOString()&lt;BR /&gt;});&lt;BR /&gt;} else {&lt;BR /&gt;// Fallback to default timeframe (last 7 days)&lt;BR /&gt;console.warn("Dashboard timeframe not available. Falling back to default timeframe (last 7 days).");&lt;BR /&gt;startTimestamp = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).getTime();&lt;BR /&gt;endTimestamp = new Date().getTime();&lt;BR /&gt;console.log("Using default timeframe:", {&lt;BR /&gt;start: new Date(startTimestamp).toISOString(),&lt;BR /&gt;end: new Date(endTimestamp).toISOString()&lt;BR /&gt;});&lt;BR /&gt;}&lt;/P&gt;
&lt;DIV&gt;But this doesn.t work, how to solve?&lt;/DIV&gt;
&lt;P class=""&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Mon, 27 Apr 2026 11:42:35 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Real-User-Monitoring/Hardcoding-USQL-Timeframe-in-Dynatrace-Notebook-Fails-for/m-p/273576#M6824</guid>
      <dc:creator>tinglikming</dc:creator>
      <dc:date>2026-04-27T11:42:35Z</dc:date>
    </item>
    <item>
      <title>Re: Hardcoding USQL Timeframe in Dynatrace Notebook Fails for Dynamic Grail Dashboards – Here’s How to Fix It</title>
      <link>https://community.dynatrace.com/t5/Real-User-Monitoring/Hardcoding-USQL-Timeframe-in-Dynatrace-Notebook-Fails-for/m-p/291228#M7187</link>
      <description>&lt;P&gt;I can't help you with solving this exact issue but in general, DQL on top of user.events and user.sessions will offer direct ways to query the data and plot it. Including counting users etc. so it's not recommended to query via javascript code and USQL RUM data captured by Dynatrace.&lt;BR /&gt;for now, the new RUM experience is in public preview until January. In the meantime - if you're not part of the preview - explore within discover dynatrace - e.g. under&amp;nbsp;&lt;A href="https://wkf10640.apps.dynatrace.com/ui/apps/dynatrace.experience.vitals/" target="_blank"&gt;https://wkf10640.apps.dynatrace.com/ui/apps/dynatrace.experience.vitals/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Dec 2025 11:56:45 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Real-User-Monitoring/Hardcoding-USQL-Timeframe-in-Dynatrace-Notebook-Fails-for/m-p/291228#M7187</guid>
      <dc:creator>paul_kapeller</dc:creator>
      <dc:date>2025-12-10T11:56:45Z</dc:date>
    </item>
  </channel>
</rss>

