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
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!
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 .
Still open to suggestions for a more elegant solution if anyone has the time...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That seems reasonable to me.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.