# Dynamic external hyperlink on scripted field

**URL:** <https://discuss.elastic.co/t/dynamic-external-hyperlink-on-scripted-field/229076>\
**Category:** Kibana\
**Created:** [April 21, 2020, 3:08pm UTC](https://discuss.elastic.co/t/dynamic-external-hyperlink-on-scripted-field/229076 "2020-04-21T15:08:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![zapho](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zapho/32/66654_2.png) [@zapho](https://discuss.elastic.co/u/zapho)\
**Post date:** [April 21, 2020, 3:08pm UTC](https://discuss.elastic.co/t/dynamic-external-hyperlink-on-scripted-field/229076/1 "2020-04-21T15:08:28Z")

</div>

Hi,

I'm using 7.5.1 ELK stack and trying to build a dashboard for our CI pipelines. I'm focusing on visualizing SonarQube quality gate data, especially highlighting error counter when code issues are detected.

I'm using a painless scripted field in Kibana to do a basic sum over json fields to detect failures:

```auto
...
for (int i = 0; i < params['_source']['component']['measures'][0]['value']['conditions'].length ; i++) {
   gateFailedCount += params['_source']['component']['measures'][0]['value']['conditions'][i]['failure'];
...
}

```

This is working as expected and I can build Metric visualization based on this scripted field.

Now I would like to make this metric (e.g. 2 gate\_failures) clickable so that users can go to the matching SonarQube url.

The url itself is buildable from the Json payload ([http://sonarqubehost/dashboard?id=](http://sonarqubehost/dashboard?id=)" + params['\_source']['component']['key']).

When I'm using this url to build the return value of the scripted field like this

```auto
...
return "<a href='http://sonarqubehost/dashboard?id=" + params['_source']['component']['key'] + "'>" + gateFailedCount + "</a>";

```

the Metric visualisation get messed up: the whole `<a href ...>` string is used as display text without any hyperlink. Looking at the DOM, the `<` and `>` symbol have been transformed into a `&lt;` and `&gt;` which explain the issue.

I also tried to declare the scripted field as a url format but could not make this work.

Is there a way to make this work?

Thanks  
Fabrice

---

<div class="post-metadata">

**Author:** ![myasonik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/myasonik/32/62369_2.png) [@myasonik](https://discuss.elastic.co/u/myasonik)\
**Post date:** [April 21, 2020, 5:52pm UTC](https://discuss.elastic.co/t/dynamic-external-hyperlink-on-scripted-field/229076/2 "2020-04-21T17:52:42Z")

</div>

If you return only the URL portion, without the HTML, using the URL field formatter should then turn that into a clickable link

---

<div class="post-metadata">

**Author:** ![zapho](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zapho/32/66654_2.png) [@zapho](https://discuss.elastic.co/u/zapho)\
**Post date:** [April 21, 2020, 9:15pm UTC](https://discuss.elastic.co/t/dynamic-external-hyperlink-on-scripted-field/229076/3 "2020-04-21T21:15:28Z")

</div>

Hi,  
Thanks for the quick response.

If I return only the URL I indeed get a clickable link but I loose the `gateFailedCount` information.  
I would to combine both: displaying the count as the anchor and the hyperlink to the sonarqube server. Something equivalent to `<a href="http://...>2</a>`

Cheers.

---

<div class="post-metadata">

**Author:** ![myasonik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/myasonik/32/62369_2.png) [@myasonik](https://discuss.elastic.co/u/myasonik)\
**Post date:** [April 21, 2020, 10:27pm UTC](https://discuss.elastic.co/t/dynamic-external-hyperlink-on-scripted-field/229076/4 "2020-04-21T22:27:21Z")

</div>

Oh, sorry, didn't catch that when I first looked.

Unfortunately that's not possible today with a scripted field. You could probably get something like that with a custom field formatter which you can load through a custom plugin or you'll have to split the field into two (the label, and the link).

There are a few related open issues in the Kibana repo that have a similar ask so it's definitely on the team's radar as something people want.

---

<div class="post-metadata">

**Author:** ![zapho](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zapho/32/66654_2.png) [@zapho](https://discuss.elastic.co/u/zapho)\
**Post date:** [April 22, 2020, 7:42am UTC](https://discuss.elastic.co/t/dynamic-external-hyperlink-on-scripted-field/229076/5 "2020-04-22T07:42:35Z")

</div>

> There are a few related open issues in the Kibana repo that have a similar ask so it's definitely on the team's radar as something people want

Yes, it would be very useful to build interactive dashboards

> you'll have to split the field into two (the label, and the link)

You mean via 2 visualizations (1 Metric and 1 Markdown for instance)? I don't think the Metric viz allows this kind of split, right?

---

<div class="post-metadata">

**Author:** ![myasonik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/myasonik/32/62369_2.png) [@myasonik](https://discuss.elastic.co/u/myasonik)\
**Post date:** [April 22, 2020, 4:12pm UTC](https://discuss.elastic.co/t/dynamic-external-hyperlink-on-scripted-field/229076/6 "2020-04-22T16:12:20Z")

</div>

> [@zapho](#):
>
> You mean via 2 visualizations (1 Metric and 1 Markdown for instance)? I don't think the Metric viz allows this kind of split, right?

Not sure what kind of visualizations you're going for but in my mind it was two columns of a table

---

<div class="post-metadata">

**Author:** ![zapho](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zapho/32/66654_2.png) [@zapho](https://discuss.elastic.co/u/zapho)\
**Post date:** [April 22, 2020, 7:08pm UTC](https://discuss.elastic.co/t/dynamic-external-hyperlink-on-scripted-field/229076/7 "2020-04-22T19:08:56Z")

</div>

Thanks for your time and advice Michail.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 20, 2020, 7:08pm UTC](https://discuss.elastic.co/t/dynamic-external-hyperlink-on-scripted-field/229076/8 "2020-05-20T19:08:59Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
