Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to address Scripted Field in a listener or a post function

Dmitry Tyomkin June 26, 2018

 I have several scripted fields and until recently they behaved quite like Custom fields, when I needed to grab their values in the listener or postfunction groovy. However, as of recent upgrade (I am not quite sure, which version) this is no longer working and in fact the script crashes when I try to treat Scripted Fields like Custom Fields. Adaptavist documentation is silent on how to use scripted fields in a listener code. Please help with a sample use example. Thanks!

1 answer

0 votes
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 26, 2018

Hello,

Could you please provide a piece of your code and the errors?

Dmitry Tyomkin June 26, 2018

Here goes. This is executed in the console, first field is regular custom field and the second is Adaptavist Scripted Field:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager

def im = ComponentAccessor.issueManager
def issue = im.getIssueObject("AAABBB")
log.warn("Executing for issue " + issue.key)

def cfv = getCustomFieldValue (issue, "customfield_XXXXX")
log.warn "Custom Field = "+cfv
def sfv = getCustomFieldValue (issue, "customfield_YYYYY")
log.warn "Scripted Field = "+sfv

It logs:

2018-06-26 15:36:44,793 WARN [runner.ScriptRunnerImpl]: Executing for issue AAABBB 2018-06-26 15:36:44,794 WARN [runner.ScriptRunnerImpl]: Custom Field = My Value

It doesn't print anything beyond that, leading me to believe that it crashes while trying to extract value from the Scripted field

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 27, 2018

What is the getCustomFieldValue() method?

You should query a value either

issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName().first(customfield_YYYYY))

or 

ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName().first(customfield_YYYYY).getValue(issue)

Try the second one for the scripted field.

Suggest an answer

Log in or Sign up to answer