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

Susan Hauth Community Champion Apr 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

This widget could not be displayed.

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 Community Champion Apr 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).

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 Community Champion Apr 25, 2014

Thank you that worked!!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Friday in Jira

New 5k User Limit and Other Cloud Updates

Hi all! Lauren here from the Enterprise Cloud marketing team.  I have some exciting Cloud updates from #AtlassianSummit that I wanted to share. We want everyone in your organization to be ab...

121 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