Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scriptrunner condition if value is present in labels field

Hocine TAMINDJOUTE June 23, 2023

Hello,

How can i do a Scriptrunner condition if value is present in labels field.

Ex :

def Labels = issue.getLabels()

def Type = issue.getIssueType().name
if((Type == "EPIC) && (Labels =="Hello")){ ...

 

Regards,

1 answer

1 accepted

3 votes
Answer accepted
Evgenii
Community Champion
June 23, 2023

Hi, @Hocine TAMINDJOUTE 

Try, please, next code:

Set<Label> labels = issue.getLabels()
String issueTypeName = issue.getIssueType().name

if((issueTypeName == "Epic") && (labels.label.contains("Hello"))) {
//Do what you wanted to do
}

p.s. it's bad idea to name variables like Labels or Type. They can interfere with imported classes 

Hocine TAMINDJOUTE June 23, 2023

Hi, @Evgenii

Thank you for the answer, below the result with error :

 

Bug JIRA.PNG

Evgenii
Community Champion
June 23, 2023

Please, add this string to imports

import com.atlassian.jira.issue.label.Label

or change string at line 7 to:

Set labels = issue.getLabels()

 

Hocine TAMINDJOUTE June 23, 2023

Thank You, it's OK

Evgenii
Community Champion
June 23, 2023

Great.

If it helped you, please accept my answer. It will help other people with similar questions.

Suggest an answer

Log in or Sign up to answer