Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Scriptrunner Behaviour - Set cf label field based on another cf label value

Hi all,

I would like another custom label field to set it's value based on another custom label field.

Here is my current code example:

def thisField = getFieldById(getFieldChanged())

def A= getFieldByName("A")

if (thisField.getValue() in (["123"]))
{
A.setFormValue("568")
}

 This seems to work well for every other field type except custom label field :(

Any ideas?

1 answer

0 votes

When in doubt ... throw some debug message.

With behaviour, I like to use the setHelpText() for immediate visual feedback

def debugMsgs = []
def thisField = getFieldById(getFieldChanged())
def A= getFieldByName("A")
debugMsgs << "A= $A"
debugMsgs << "thisField = $thisField"
debugMsgs << "thisField.value = $thisField.value"


if (thisField.getValue() in (["123"]))
{
debugMsgs << "thisField.value found in (["123"])"
A.setFormValue("568")
debugMsgs << "A.value = $A.value"
}
A.setHelpText(debugMsgs .join('<br>'))

The one thing I would try different  from your code is to remove the parens around ["123"] 

Hey!

I gave your script a go and it's erroring out on the "123". Unfortunately as my groovy knowledge is "just beginner" I was unable to solve it :(

debugMsgs << "thisField.value found in (["123"])"

I did try setting different field type (Text) and all seemed to work great. And I have got single and multi select to work. I can also get the system label field to work, just not custom label fields to work. Are they not supported or a bug?

Try it like this:

def debugMsgs = []
def thisField = getFieldById(getFieldChanged())
def A= getFieldByName("A")
debugMsgs << "A= $A"
debugMsgs << "thisField = $thisField"
debugMsgs << "thisField.value = $thisField.value"

def valueMap = ['123':'568']
if (valueMap.containsKey(thisField.value))
{
debugMsgs << "thisField.value found in ${valueMap}"
A.setFormValue("568")
debugMsgs << "A.value = $A.value"
}
A.setHelpText(debugMsgs .join('<br>'))

You'll want to change valueMap. The left side is the value in thisField" that triggers the 'right-side' label. If you have more, you add them comma sparated.

This worked!

It does show the field should be receiving the values. But it still is not adding the label?

A= Form field ID: customfield_11858, value: 568
thisField = Form field ID: customfield_11052, value: 123
thisField.value = 123
thisField.value found in [123:568]
A.value = 568   

Not sure what's going on there ... it's working for me.

Here I use the code exactly as is except for def A= getFieldByName("Theme")

The script is put against a random text field ... if I type "123" in my text field, I get this:

2021-05-05 10_47_30-Edit Issue _ PLV-4408 - JIRA Dev.png

Hmmmmm I still cannot get it to work...

I wonder if it's a version issue of Jira/Script runner?

Code:

def debugMsgs = []
def thisField = getFieldById(getFieldChanged())
def A= getFieldByName("Region")
debugMsgs << "A= $A"
debugMsgs << "thisField = $thisField"
debugMsgs << "thisField.value = $thisField.value"

def valueMap = ['123':'USA']
if (valueMap.containsKey(thisField.value))
{
debugMsgs << "thisField.value found in ${valueMap}"
A.setFormValue("USA")
debugMsgs << "A.value = $A.value"
}
A.setHelpText(debugMsgs .join('<br>'))

 Image:

Image.png

Perhaps ... I do see a slightly different styling of your Label field than mine.

I'm on Jira 8.13.6 (Software+JSM)

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you