First time using Script Field - GroovyRunner - Can't seem to get the right syntax

Susan Hauth _Jira Queen_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 25, 2014

Hi,

I'm not a programmer, so hoping someone can help me. I'm trying to use a scripted field to take the value of our custom field "Department" and return the GL Code for it. This is what I put in. It doesn't seem to break anything, but when I try to preview it with an issue that has Department = Global, It just shows nothing. HELP.

def Department = getCustomFieldValue("Department")
def DeptCode
if (Department == "Global") {DeptCode = "1001"}
else if (Department == "Client Services") { DeptCode = "1002"}
return DeptCode

1 answer

1 accepted

1 vote
Answer accepted
Boris Georgiev _Appfire_
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.
April 25, 2014

Does this issue has the Department field set ?

Alsto try first this piece of code to see what value is returned:

def Department = getCustomFieldValue("Department")
return Department

What is the type of the Department custom field ? Is it text field or some other ?

Susan Hauth _Jira Queen_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 25, 2014

Hi,

I added that in and then tried preview and this is what I got:

Global
The indexer for this field expects a java.lang.String but the script returned a com.atlassian.jira.issue.customfields.option.LazyLoadedOption - this will cause problems.
So it did read the custom field Department (which is a single select field).
Boris Georgiev _Appfire_
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.
April 25, 2014

So then change the script as follows:

def Department = getCustomFieldValue("Department").value
def DeptCode
if (Department == "Global") {DeptCode = "1001"}
else if (Department == "Client Services") { DeptCode = "1002"}
return DeptCode

Susan Hauth _Jira Queen_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 25, 2014

Thank you that worked!!

Suggest an answer

Log in or Sign up to answer