05 Jun 2026 08:15 AM
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:
export default async function (context) {
console.log(context)
const cluster = context.variables.Cluster;
...
}The console out:
{
"$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?
Solved! Go to Solution.
05 Jun 2026 02:06 PM
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
05 Jun 2026 03:11 PM
Yeah, you should just be able to reference it in the code with the standard $varName syntax.
08 Jun 2026 05:37 AM
Thank you @AndyHubert and @dannemca 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:
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);
}
Featured Posts