Not able to get the value of a custom field using Groovy Script.

Nikhil February 12, 2013

I made a custom field whose value am polpulating from a csv file which I have uploaded from jira console. I configured that field on jira screen and able to see the options there. Now I am trying to get the checked values in my groovy script & using the below code for that:

ComponentManager componentManager = ComponentManager.getInstance();

CustomFieldManager customFieldManager = componentManager.getCustomFieldManager();

CustomField svnPathcustomField = customFieldManager.getCustomFieldObject("customfield_12681");

log.error("svnPathcustomField -->"+svnPathcustomField);

String[] svnPath = (String[]) issue.getCustomFieldValue(svnPathcustomField);

log.error("svnPath -->"+svnPath);

In logs the value of "svnPath" is coming null... Please help.

Thanks.

5 answers

1 accepted

0 votes
Answer accepted
JamieA
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.
February 12, 2013

> The script failed : javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: o for class: Script24

What's this...? Where is "o" in your code? Can you paste the full script somewhere.

Are you sure the field has options selected?

Nikhil February 12, 2013

Hey thanks Jamie :) .. by mistake i have added '0' and now m getting the values...

0 votes
Nikhil February 12, 2013

Tried this but again got the value as "null".. :( below is the error on console -

2013-02-13 10:09:28,757 ajp-bio-8009-exec-110 ERROR 502005038 609x16122x1 z4rdb 3.209.125.241 /secure/CommentAssignIssue.jspa [onresolve.jira.groovy.GroovyRunner] svnPath: null

2013-02-13 10:09:28,781 ajp-bio-8009-exec-110 ERROR 502005038 609x16122x1 z4rdb 3.209.125.241 /secure/CommentAssignIssue.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: o for class: Script24

0 votes
Nikhil February 12, 2013

Field is of type "Multi check box". And I am using script in validation part and trying to get the value in that script.

0 votes
JamieA
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.
February 12, 2013

What type of field is it?

Does the issue definitely have a value for that field?

What context is the script running in, eg post-function?

0 votes
JamieA
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.
February 12, 2013

You should be getting an error not null - you can't cast a collection of Option objects to a String[] - I think. Remove the cast and static typing and just log the return value:

def svnPath = issue.getCustomFieldValue(svnPathcustomField)
log.warn "svnPath: $svnPath"

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events