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

0 votes
Accepted answer

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
Community showcase
Published Oct 31, 2018 in Marketplace Apps

Marketplace Spotlight: Zephyr

Hello Atlassian Community! Each month, we run a series of Spotlights to highlight Marketplace vendors and apps that our team thinks this Community would find valuable. In last month's Spotlig...

415 views 0 3
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