Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Groovy Script: Ignore script if category = null Edited

I'm using ScriptRunner and I'm getting errors when the following script runs and it comes across a category that is blank.  I would like to be able to add a check, so if category = null then do not run

Here's the code I have so far:

def issueProject = issue.getProjectObject();
def projectCategory = issueProject.getProjectCategory();
def categoryName = "";

if (categoryName) {
categoryName = projectCategory.getName();
}

return categoryName;

 

I tried replacing if statement with:

if (projectCategory.getName()) {
categoryName = projectCategory.getName();
}

But it throws back an error.

1 answer

1 accepted

0 votes
Answer accepted

There's a mistake in:

def projectCategory = issueProject.getProjectCategory();
def categoryName = "";

if (categoryName) {
categoryName = projectCategory.getName();
}

You're getting a project category from the project, but then setting the categoryName to blank, so "if (categoryName)" is always going to be false. 

I think you meant:

if (projectCategory) {
categoryName = projectCategory.getName();
}

That checks the projectCategory and sets the categoryName if there is a category for the project

Thank you SO much!  This was driving me crazy! :)

Suggest an answer

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

⏰ Day in the life of a Jira Admin!

Hello Community! We thoroughly enjoyed this just-for-fun conversation in the Jira Admin Group about what it's like to be a Jira Admin. For #JiraJuly, our talented designers created these graphics t...

699 views 2 20
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you