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,455,528
Community Members
 
Community Events
175
Community Groups

Scriptrunner behaviour: Using wildcards to find values

Hi there,

I'm trying to to set up a behaviour when a value contains a specific number:

 

def multiSelectField = getFieldById("customfield_164118");
def multiSelectFieldValue = multiSelectField.value as List
if (multiSelectFieldValue.contains(4000)) {
     wertcn.setFormValue("CN")
     wertus.setFormValue("US")
My value is Test_4000_test. Is there a way to use wildcards?

1 answer

1 accepted

1 vote
Answer accepted

Hi @Dustin Glienke 

Can you try instead of contains() the following?

matches("4000")

Hi Alex,

thx for replying quickly. Unfortunately I'm receiving the following error:

2022-12-08 13_55_14-Window.png

Is it possible to paste here you code so that I can perform some tests?

Yes of course:

import com.onresolve.jira.groovy.user.FieldBehaviours
import org.apache.log4j.Logger
import org.apache.log4j.Level
import groovy.transform.BaseScript

def material = getFieldById("customfield_164118");
def wertus = getFieldById("customfield_63900");
def wertcn = getFieldById("customfield_63901");

@BaseScript FieldBehaviours fieldBehaviours
def log = Logger.getLogger(getClass())

def multiSelectField = getFieldById("customfield_164118");

def multiSelectFieldValue = multiSelectField.value as List


// If value is null
if (multiSelectFieldValue == [null]) {
}

else if (multiSelectFieldValue.contains(4000)) {
     wertcn.setFormValue("CN")
     wertus.setFormValue("US")
}
the field material is a multi select list. Test value is Test_4000_test

@Dustin Glienke just noticed on your script that on material you have this id:

customfield_164118

Is this correct? It has a six figure numerical id.

Yes it is correct:

2022-12-08 14_26_43-Window.png

Our system has a strange count system, we have not that many fields

@Dustin Glienke the following script worked for me:

def text = getFieldByName("Text field (akox)")
def multiSelectField = getFieldById(getFieldChanged())
def multiSelectFieldValue = multiSelectField.value as List
def myValues =multiSelectFieldValue.toString()
def result = (myValues =~ /\d+/).findAll()

if (multiSelectFieldValue == [null] ) {
}
  else {
    assert result == ["4000"]
    text.setFormValue ("Found 4000")
  }
  • The above script was placed on my multi select field. So this is were you place it.
  • You replace the text variable with your wertus and wertcn variables
  • You place your setFormValues below the "assert"
  • You delete my text variable

 

Let me know if that works out for you!

Unfortunately it does not work but i don't know why:

def wertus = getFieldById("customfield_63900");
def wertcn = getFieldById("customfield_63901");

def multiSelectField = getFieldById(getFieldChanged())
def multiSelectFieldValue = multiSelectField.value as List
def myValues =multiSelectFieldValue.toString()
def result = (myValues =~ /\d+/).findAll()

if (multiSelectFieldValue == [null] ) {
}
  else {
    assert result == ["4000"]
wertcn.setFormValue("CN")
wertus.setFormValue("US")
//text.setFormValue ("Found 4000")
}

Does anything happen or not?

Nothing happend

@Dustin Glienke did you try following the guidelines I gave you with code? This code works on my instance without any problem. What kind of fields are wertcn and wertus?

Hi Alex,

I found a solution. The function contains is the right one. I figured out to use this 'value' instead of "value". Now it is working. Thanks for your help!

import com.onresolve.jira.groovy.user.FieldBehaviours

import org.apache.log4j.Logger

import org.apache.log4j.Level

import groovy.transform.BaseScript

def material = getFieldById("customfield_164118");

def wertus = getFieldById("customfield_63900");

def wertcn = getFieldById("customfield_63901");

def wertde = getFieldById("customfield_63902");

@BaseScript FieldBehaviours fieldBehaviours

def log = Logger.getLogger(getClass())

def multiSelectField = getFieldById("customfield_164118");

def multiSelectFieldValue = multiSelectField.value as List

def myValues =multiSelectFieldValue.toString()

// If value is null

if (myValues.contains('4000')) {

wertus.setFormValue("US")

}

if (myValues.contains('5000')){

     wertcn.setFormValue("CN")

}

if (myValues.contains('4000')==false) {

wertus.setFormValue("")

}

if (myValues.contains('5000')==false){

     wertcn.setFormValue("")

}

Suggest an answer

Log in or Sign up to answer