Scripted fields values not getting populated on visualize but are populated during discover

Hi Kibana Experts,

I am using Kibana scripted fields using painless to populate a URL like this:

Url Template : https://dummy_url?branch={{value}}&id=abc
Script: 
if (!doc['branch_name'].empty) {
    return (doc['branch_name'].value)
}

When I access this scripted field for my index pattern in Discover, the value gets populated correctly and I can access the URL but when I am accessing the same scripted field in "data table" Visualize, the URL is missing the value populated by {{value}}.

Can you please help on how I can populate the scripted field correctly on data table visualize?

I am using Kibana Version, 5.4.1.

Thanks

Can you show the doc?

It is a huge doc but this specific field has values like:

branch_name

develop
master
release/f1
release/f2

and the field details are like the screenshot.

Where is that URL? How is it populated?
I did not understand your requirements fully.

The URL is populated by the scripted field like the snapshot and I want to access that URL in my data table visualize but the URL is missing the value populated by {{value}}.
It shows like this for all the rows:

https://dummy_url?branch=&id=abc

Try using {{rawValue}} instead of {{value}}

Already tried rawValue but that didn't help.

Try putting url?id=abc&branch={{value}}
so your arameter will be at the end?!

Tried that too but that didn't work either

I am using v 7.9.1 and it works fine.
Last idea, try adding keyword
Like

if (!doc['branch_name.keyword'].empty) {
    return (doc['branch_name.keyword'].value)
}

If that doesn't work it might be a version-specific bug?
Try contacting Elastic for this issue.

Tried keyword too but that doesn't work either.