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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,089 views 13 18
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot