check if a string is part of another string

Tomas Arguinzones Yahoo
Contributor
May 31, 2017

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
Answer accepted
Daniel Yelamos [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 5, 2017

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

 

Tomas Arguinzones Yahoo
Contributor
June 12, 2017

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
TAGS
AUG Leaders

Atlassian Community Events