# Dashboard Variables in Code Tile

**URL:** <https://community.dynatrace.com/t/dashboard-variables-in-code-tile/56106>\
**Category:** Dashboarding\
**Tags:** latest-dynatrace, dashboards\
**Created:** [June 5, 2026, 7:15am UTC](https://community.dynatrace.com/t/dashboard-variables-in-code-tile/56106 "2026-06-05T07:15:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mikko](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@Mikko](https://community.dynatrace.com/u/Mikko)\
**Post date:** [June 5, 2026, 7:15am UTC](https://community.dynatrace.com/t/dashboard-variables-in-code-tile/56106/1 "2026-06-05T07:15:36Z")

</div>

I’m building a dashboard with a code tile and I want to use a variable to filter my query. The variable is set on the dashboard, but I cannot find a way to reference it inside the code tile. I tried getting it through context:

```javascript
export default async function (context) {
  console.log(context)
  const cluster = context.variables.Cluster;
  ...
}

```

The console out:

```markup
{
  "$dt_timeframe_from": "2026-06-05T04:47:00.000Z",
  "$dt_timeframe_to": "2026-06-05T06:47:00.000Z"
}

```

So basically my question is that is there any way to reference the Dashboard Variable within the code tile?

---

<div class="post-metadata">

**Author:** ![dannemca](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/dannemca/32/7215_2.png) [@dannemca](https://community.dynatrace.com/u/dannemca)\
**Post date:** [June 5, 2026, 1:06pm UTC](https://community.dynatrace.com/t/dashboard-variables-in-code-tile/56106/2 "2026-06-05T13:06:57Z")

</div>

Have you tried reference it “as is”? $yourvarname

I have a var called $Tenant in one of my Dashboards, and in the code tile I just mention the var as is, $Tenant

 ![Screenshot 2026-06-05 100551.png](https://global.discourse-cdn.com/dynatrace/original/3X/2/1/21ab0b724e6652f82ff73ba0ecedb5c8427b2867.png)

---

<div class="post-metadata">

**Author:** ![AndyHubert](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/andyhubert/32/4246_2.png) [@AndyHubert](https://community.dynatrace.com/u/AndyHubert)\
**Post date:** [June 5, 2026, 2:11pm UTC](https://community.dynatrace.com/t/dashboard-variables-in-code-tile/56106/3 "2026-06-05T14:11:51Z")

</div>

Yeah, you should just be able to reference it in the code with the standard $varName syntax.

 ![AndyHubert_0-1780668686484.png](https://global.discourse-cdn.com/dynatrace/original/3X/9/2/9278d8327de7fd44cac8b9cd35557cfd21d36c81.png)

---

<div class="post-metadata">

**Author:** ![Mikko](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@Mikko](https://community.dynatrace.com/u/Mikko)\
**Post date:** [June 8, 2026, 4:37am UTC](https://community.dynatrace.com/t/dashboard-variables-in-code-tile/56106/4 "2026-06-08T04:37:26Z")

</div>

Thank you&nbsp;[@AndyHubert](https://community.dynatrace.com/user/44872)&nbsp;and&nbsp;[@dannemca](https://community.dynatrace.com/user/18264)&nbsp;for the help. TBH I didn’t try to ref the $Variable with the standard syntax and it worked. I still needed to reference is through the context for some reason and thought, I’d share it here if someone else is having similar issues. This solution worked for me:

```javascript
export default async function (context) {
  const cluster = context.$Cluster || null;
    if (!cluster) {
      console.error("Cluster variable is not defined");
      return;
  }

  const clusterName = cluster.slice(10); // Get the hostgroup name out of a cluster name
  console.log(`Fetching namespaces for cluster: ${clusterName}`);

  return await checkInjectionFailures(clusterName);
}

```
