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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

354 views 0 6
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