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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,560,577
Community Members
 
Community Events
185
Community Groups

Groovy expression using "contains" comparing with a variable

Edited

Hi,

I am using a ScriptRunner Script Listener utilizing

(issue.getSummary().contains("Escalation EMEA Project XY"))

which works pretty well.

I have an use case where I'd like to replace the predefined string with "contains" using a variable. Is this possible from Groovy scripts?

(issue.getSummary().equals(projectEscalation))

Where "projectEscalation" is a defined variable (basically working!) - I had no success.

Is there anything I am missing?

Basically I want to do further checks if the summary matches a specific string and if this is the case some other logics apply (already implemented and works).

Thanks,

Birgit

 

2 answers

1 accepted

0 votes
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Sep 29, 2018

This is just about using variables in groovy.  Try replacing

(issue.getSummary().contains("Escalation EMEA Project XY"))

with

def thingy = "Escalation EMEA Project XY"
(issue.getSummary().contains(thingy))

Note that in your question, you had also swapped "contains" for an exact match of "equals"

Thanks! I think I got an idea how it is supposed to work. While "equals" seems to work "contains" throws an error.

 

[Static type checking] - Cannot find matching method
java.lang.String#contains(com.atlassian.jira.issue.fields.CustomField).
Please check if the declared type is right and if the method exists.
Possible solutions: contain(java.lang.CharSequence),
contains(java.lang.CharSequence), toString(), toString(), toString(), notify() @ line 19, column 4

(issue.getSummary().contains(ticketReferenceValue))


Where the variables are defined as follows:

def ticketReference = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10302")
def ticketReferenceValue = issue.getCustomFieldValue(ticketReference)


A typical content of the customfield is something like
[Ticket#123456]
I am unsure if the content is the reason for the error message (especially for the brackets or the hash sign).

Is there maybe an easy way around to fix it? That would be fabulous. Otherwise I'd consider to match agains at least a static string.

It is all solved now. Please ignore my previous message.

The last step missing was to use String instead of def.

 

Thanks to Nic for the good hint that pointed to the right direction.
I will mark the question as answered now.

Best regards,
Birgit

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events