check if a string is part of another string

Hi,

I am configuring a script listener in script runner for JIRA and need to implement the following:  I have a multiple select custom field and need to check  everytime that field is updated, the value "Integrations" was present in the previous value and in the new value. So far I have this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def change = event?.getChangeLog()?.getRelated("ChildChangeItem").find {it.field == "Scrum Team"}


if (change) {
     def old_field_value = change.oldstring;
     def new_field_value = change.newstring;
     log.warn("previous value: " + old_field_value)
     log.warn("new value: " + new_field_value)
}else
     log.warn("there was not change")

 

how do I check whether the string "Integrations" was present or not in old_field_value? Similarly, how do I check whether the string "Integrations" is present or not in new_field_value?

Thank you for your assistance

1 answer

1 accepted

Hello Tomas:

if your old_field_value is a string, you can use a few methods that you can see here

I would personally use something like this:

if(old_field_value.count("Integrations")>0){
      log.info("String: Integrations is present")
}

and you can check the same with your other variable new_field_variable so long as they are both Strings

If I can be of further assistance please let me know.

Cheers!

Dyelamos

 

Hi Daniel....Thank you for your assistance...I used "contains" from the list of methods you sent me...good info..I appreciate it! Thanks

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Tuesday in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

130 views 0 4
Read article

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