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

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Wednesday in Jira

Join our webinar: How 1B+ feature flag events helped us build the new Jira

Every time you release software, there's a bit of risk – that there's a bug, that something breaks, or that the feature doesn't resonate with customers. Feature flagging helps make high stakes s...

133 views 0 3
Join discussion

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