Use Behaviour plugin scripted field value

Hi - I have a Scriptrunner Scripted field that works fine, and correctly returns one of two values : 'Planned' or 'Un-Planned'. I have used a "Exact Text Searcher (natural)" as the search selector for the script field, which allows me to use the result of the scripted field in all the dashboard widgets and reports....except a 3rd party barchart plugin called 'Barcharts for JIRA'. For some reason it cannot pickup on the value of my scripted field (or epic links either, if that's relevant).

My idea was to create a second, normal text field (which the bar chart plugin can handle), and copy the value of the scripted field into the text field. I have tried using the Behaviour module in script runner, but it is returning the value of the scripted field as 'null'

I have been using basically this syntax:

def targetVal = getFieldByName("customfield_10836")
def sourceVal = getFieldByName("Planned/Unplanned")
targetVal.setFormValue(sourceVal)

I also tired adding .value, .text, .toString() etc.to the end of the targetVal line, but I just cant seem to capture the actual textual value of my script field.

What am I doing wrong? Could anyone give me example code some example code to put in the initialize function of the behaviour

2 answers

1 accepted

This widget could not be displayed.

Hi, so I got the best solution possible in the end; the guys at TNG tech who make the plugin released a new version (3.3) that natively/automatically supports scripted fields!

No need for behaviours, listeners etc. Although I enjoyed trying to workaround my original problem, even if it was long winded!

This widget could not be displayed.

Hi Paddy,

Scripted fields cannot be added in a screen therefore getFieldByName("Scripted Field A") will return null every time. Instead you can retrieve it's value via the CustomFieldManager. So in a behaviour, in order to get the value of a scripted field:

import com.atlassian.jira.component.ComponentAccessor


def scriptedField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Scripted Field")
def scriptedFieldValue = underlyingIssue?.getCustomFieldValue(scriptedField)

Hi Thanos,

Thank you, that got me a bit closer to achieving what I want. I now am able to read the script field's value and copy it into my 'slave' text field...but...something is happening I don't understand.

My Script field and my 'slave' text field are on my 'view issue' screen. Neither of them are on my 'create issue' screen (intentionally). If I create a new issue, and then navigate to it, the script field works as it always has done and displays a value, but my slave field is initially blank. If I hit the 'edit' button, change nothing and simply hit the update button, the edit screen disappears and now back on the view issue screen the behavior you helped me with fires, and successfully copys the value of the script field to the slave field.

Why does the behaviour only fire by going to edit mode? And is there a way to change this so it happens automatically when an issue is initially created?

I intend to eventually hide this slave field eventually once I get it to work, if this affects the answer...

Any help or advice appreciated

Paddy - Behaviours have some limitations, one of which is that they're JavaScript-based, and so they're limited to the fields available on a given screen. You might be able to work around the issue by adding your slave field to the create screen, then using the behaviour to make it hidden.

As a side note, you might file a bug with the makers of Bar Charts.

Hi - I also tried adding the slave field to the create screen, but no luck either. I did raise an issue with the vendor to ask if support could be added for scripted fields... 

So, it's a bit of a hack, but you could use a Scripted Service to periodically go through the issues where the slave field doesn't match the scripted field and copy the values over.

Hi - so I actually managed to achieve what I needed. I used a custom event listener that fires when a new issue is created in my project. I check the script field and slave field exist in the issue that fired it, then check the issue type, and if it is the relevant one I grab the value of the script field and write it into the slave field. The original behaviour then works and keeps the field in sync if the issue is ever edited. Clunky, but works smile

Still open to suggestions for a more elegant solution if anyone has the time...

That seems reasonable to me.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published Jul 25, 2018 in Marketplace Apps

Jira Cloud and Bitbucket Cloud Integration with Microsoft Teams

One of the newest products in the Microsoft family - Microsoft Teams,  is a chat-based hub for teamwork that integrates all the people, content, and tools your team needs to be more engaged and ...

733 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you