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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Apr 17, 2018 in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

767 views 2 19
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