How Do I Truncate a Variable Value's String?

Version: Grafana Version: 8.0.6

What are you trying to achieve?
I am trying to use an existing variable value that is selected from a CUSTOM variable and select a subset of the value. The custom variable has a list of 4 API names defined in Custom Options(comma separated list). I need to reference this variable’s value in another panel query. I’ll use this value to reference an AWS Synthetic Canary name. The name of the Canary is constructed using a 13 character prefix that precedes the API name. The prefix + the Application name cannot exceed 20 characters, effectively this means the API name I used cannot be > 7 characters.

I need to reference this custom variable, but I only want the first 7 characters of it.

So, if the user select “policydata” from the Custom variable’s drop-down, I need to transform the value into “policyd”.

How are you trying to achieve it?
I was hoping that I could do this in-line instead of creating a new variable. For example: {queryvariable.substring(0,6)}. I know that substring functions do not exist in Advanced Variable Format Options in Grafana yet. But I’d like to essentially only select N number of characters (in this case N=7).

What happened?
Have not yet determined if this is possible.

What did you expect to happen?
Nothing implemented yet. Not sure how to make this happen.

Can you copy/paste the configuration(s) that you are having problems with?
This isn’t a configuration issue. I am seeking guidance on how to truncate an existing variable value.

Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
No.

Did you follow any online instructions? If so, what is the URL?
I’ve been through the templatings guide and I can’t find out if what I’m trying to do is possible or not. This info was obtained from the Grafana support site here:

2 Likes

This topic was automatically closed after 365 days. New replies are no longer allowed.