VolkovLabs / volkovlabs-dynamictext-panel

Business Text Panel for @grafana
https://docs.volkovlabs.io
Apache License 2.0
78 stars 14 forks source link

Use dashboard variable in the JS-Code section #180

Closed tichribra closed 1 year ago

tichribra commented 1 year ago

Hello,

I would like to know if it is possible to use grafana dashboard variables inside the JavaScript code section. I tried it with the common way "$variableName" like in the data manipulation plugin but it doesn't work.

akshay996 commented 1 year ago

I am facing the same issue. I am trying to create a JSON object and then trying to pass dashboard variables in JS Code section but when I view the JSON in Console, it doesn't replace it with dashboard variable (console screenshot attached below)

image

akshay996 commented 1 year ago

Solution: Wrap it inside built-in function repaceVariables("${var_name}")

Example: image

yosiasz commented 1 year ago

@akshay996 thanks for that idea but when I use it I get repaceVariables is not defined any idea?

yosiasz commented 1 year ago

ok got it !

const bonjour = replaceVariables("${composant}");
console.log(bonjour.toUpperCase())
mikhail-vl commented 1 year ago

replaceVariables is mentioned in the documentation (https://volkovlabs.io/plugins/volkovlabs-dynamictext-panel/code/), but we don't provide any examples of using it.

I will update the documentation to make it clear.

mikhail-vl commented 1 year ago

Updated in the documentation: https://volkovlabs.io/plugins/volkovlabs-dynamictext-panel/code/