Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,298,337
Community Members
 
Community Events
165
Community Groups

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 Confluence

An update on Confluence Cloud customer feedback – June 2022

Hi everyone, We’re always looking at how to improve Confluence and customer feedback plays an important role in making sure we're investing in the areas that will bring the most value to the most c...

180 views 1 3
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